0

我在 Jupyter Notebook 中运行 Python,并且以下代码在 Notebook 中运行良好:

from bokeh.charts import BoxPlot, show
from bokeh.io import output_notebook
output_notebook ()

df = myfile2

p = BoxPlot(df, values='Total Spending', label=['Market'],color='Market', marker='square',
        whisker_color='black',legend=False, plot_width=800, plot_height=600,
        title="Total Spending, February 2017)")

p.xaxis.major_label_orientation = "horizontal"

show(p)

我的问题是 y 轴显示以下值和刻度线:

1000-
    -
    -
    -
    -
 500-
    -
    -
    -
    -
   0-

我想格式化该 y 轴,以便值显示如下:

   1000
    900
    800
    700
    ...
      0

可以在 Bokeh 中完成吗?

4

1 回答 1

1

所以,我遇到了同样的问题,并在这个威胁中找到了解决方案:https ://stackoverflow.com/a/27878536/2806632

基本上,您想要的是创建没有轴的图形,然后使用您的格式添加轴。类似的东西:

from bokeh.models import SingleIntervalTicker, LinearAxis
from bokeh.charts import BoxPlot, show
from bokeh.io import output_notebook
output_notebook ()

df = myfile2

# See that x_axis_type is now None
p = BoxPlot(df, values='Total Spending', label=['Market'],color='Market', marker='square',
        whisker_color='black',legend=False, plot_width=800, plot_height=600,
        title="Total Spending, February 2017)", x_axis_type=None)


# Interval one, assuming your values where already (0,100,200...)
ticker = SingleIntervalTicker(interval=1, num_minor_ticks=0)
yaxis = LinearAxis(ticker=ticker)
p.add_layout(yaxis, 'left')
# I'm pretty sure you won't need this: p.xaxis.major_label_orientation = "horizontal"

show(p)
于 2017-04-28T09:40:16.897 回答