如何改变博克图表轴标签大小?

2024-04-29 04:55:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是bokeh0.11.1,pip install --upgrade bokeh报告我使用的是最新版本。在

如果使用,我可以确定如何更改bokeh x轴文本大小参数博克。绘图但在博克图表中没有。下面的代码,如果在Jupyter笔记本中运行,将显示非常紧密的x轴标签。我希望字体小一点--有什么窍门吗?在

import pandas as pd
data = pd.read_csv("https://raw.githubusercontent.com/pm0kjp/datastore/master/river_data.csv")

import bokeh.charts
import bokeh.plotting
bokeh.plotting.output_notebook()

tooltips=[
    ('Water Site ', '$x'),
    ('Average of Enterococcus Count ', '$y')
]

p = bokeh.charts.Scatter(data, x='Site', y='EnteroCount', 
        title="Swimming Holes By Average Enterococcus Count", ylabel="Enterococcus Count", tooltips=tooltips)
p.width=1000
bokeh.charts.show(p)

文档表明我可以简单地添加 p.yaxis.axis_label_text_font_size = "8pt",但如果我这样做,我会得到错误 AttributeError: 'Chart' object has no attribute 'yaxis'。在


Tags: installpipcsvimportdatacountbokehsite
1条回答
网友
1楼 · 发布于 2024-04-29 04:55:31

有一个完整的用户指南部分专门介绍styling visual properties,包括如何设置axis labels的样式。由于bokeh.chartsbokeh.plotting创建的绘图都解析为同一组低级对象,因此在这两种情况下设置属性都是相同的:

p.yaxis.axis_label_text_font_size = "8pt"

以下是0.12.3的完整工作示例:

^{pr2}$

这是一个带有微小y轴标签的结果:

enter image description here


如果由于某些原因无法更新到版本0.12,可以执行以下操作:

In [12]: from bokeh.models import Axis

In [13]: p.select(type=Axis)
Out[13]:
[LinearAxis(id='54b21a9f-22e0-4f7a-b809-8d4f755a444e', ...),
 CategoricalAxis(id='b52e7b2c-2b18-4578-be42-4fbfba17af60', ...)]

获取所有axis对象的hold,您可以通过设置它们的axis_label_text_font_size属性直接修改这些对象。但你得弄清楚哪个轴是x轴,哪个轴是y轴

相关问题 更多 >