我在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中完成吗?
答案 0 :(得分: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)