【问题标题】:How do I make my Bokeh Boxplot show the values of all the tick marks on the y-axis?如何让我的散景箱线图显示 y 轴上所有刻度线的值?
【发布时间】:2017-04-03 12:13:26
【问题描述】:

我在 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 中完成吗?

【问题讨论】:

    标签: python jupyter-notebook bokeh yaxis


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 2016-05-24
      相关资源
      最近更新 更多