固定散景散點圖中的軸間距(刻度) (Fixing axis spacing (ticks) in Bokeh scatter plots)


問題描述

固定散景散點圖中的軸間距(刻度) (Fixing axis spacing (ticks) in Bokeh scatter plots)

我正在使用散景圖生成散點圖,每個 X 值具有不同的 Y 值。當 Bokeh 生成繪圖時,它會根據繪製的值的數量自動填充 x 軸間距。無論單個數據點的數量如何,我都希望 x 軸上的所有值均勻分佈。我已經研究過手動設置刻度,但看起來我必須使用這種方法自己設置間距(即指定確切的位置)。我希望它能夠像繪製奇異 x,y 值對時那樣自動均勻地設置間距。可以這樣做嗎?

這是一個顯示行為的示例。

import pandas
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource

days =['Mon','Mon','Mon', 'Tues', 'Tues', 'Weds','Weds','Weds','Weds']
vals = [1,3,5,2,3,6,3,2,4]

df = pandas.DataFrame({'Day': days, 'Values':vals})

source = ColumnDataSource(df)

p = figure(x_range=df['Day'].tolist())
p.circle(x='Day', y='Values', source=source)
show(p)

參考解法

方法 1:

You are passing a list of strings as the range. This creates a categorical axis. However, the list of categories for the range is expected to be unique, with no duplicates. You are passing a list with duplicate values. This is actually invalid usage, and the result is undefined behavior. You should pass a unique list of categorical factors, in the order you want them to appear, for the range.

(by JeremyDbigreddot)

參考文件

  1. Fixing axis spacing (ticks) in Bokeh scatter plots (CC BY‑SA 2.5/3.0/4.0)

#scatter-plot #Python #bokeh






相關問題

matplotlib:重繪前清除散點數據 (matplotlib: clearing the scatter data before redrawing)

使用 matplotlib 保存散點圖動畫 (Saving scatterplot animations with matplotlib)

在 matplotlib 中圍繞散點圖中的數據點繪製平滑多邊形 (draw a smooth polygon around data points in a scatter plot, in matplotlib)

Java:非常簡單的散點圖實用程序 (Java: Really simple scatter plot utility)

如何在多個圖中選擇一個要編輯的圖? (How to select one plot to be edit in multiple plots?)

d3js散點圖自動更新不起作用 (d3js scatter plot auto update doesnt work)

散點圖中的重疊趨勢線,R (Overlapping Trend Lines in scatterplots, R)

DC.JS 散點圖選擇 (DC.JS scatterplot chart selection)

固定散景散點圖中的軸間距(刻度) (Fixing axis spacing (ticks) in Bokeh scatter plots)

如何在顏色條上繪製散點圖? (How to plot scatter plot points on a colorbar?)

如何在散點圖中以均勻間隔更改 x 軸值? (How to change x axis value with even interval in scatter plot?)

如何在散點圖(地理地圖)上標註數據? (How to annotate data on the scatter plot (geo map)?)







留言討論