简体   繁体   English

x 轴名称在散景图之外

[英]x-axis name is outside bokeh figure

I have build a barchart in Bokeh but have the problem that the name on the left-most side of the x-axis is outside the figure.我在 Bokeh 中构建了一个条形图,但问题是 x 轴最左侧的名称在图形之外。 My code looks like this:我的代码如下所示:

source2 = ColumnDataSource(data=dict(district=df2.district,
                                   areaRatio=df2.areaRatio,                                   areaRatioStr=round(df2.areaRatio,0)))

# Figure
p2 = figure(x_range=df2.district,plot_height=300,plot_width=500,
           y_range= ranges.Range1d(start=0,end=1800),
           title="Trees pr. km²")

# Bar chart
p2.vbar(x='district',top='areaRatio',source = df2,width=0.9,color='green')

# remove the grid
p2.xgrid.grid_line_color=None
p2.ygrid.grid_line_color=None
# Make sure bars stat at 0
p2.y_range.start = 0
# Turn the x-labels
p2.xaxis.major_label_orientation = 0.5
# remove - y-axis
p2.yaxis.visible = False
# Remove the toolbar
p2.toolbar_location=None
# Remove the grey box around the plot
p2.outline_line_color = None

# add labels
labels2 = LabelSet(x='district', y='areaRatio', text='areaRatioStr', level='glyph',
                  x_offset=-20, y_offset=0, source=source2, render_mode='canvas',
                  text_font_size="14pt")

# add hover tool
p2.add_tools(HoverTool(tooltips = [('Trees pr. km²','@areaRatio{0.0}')]))
p2.add_layout(labels2)
show(p2)

In the figure below the left bar is suppose to have the name 'Amager Vest' but at the moment only 'er Vest' is visible.在下图中,左栏假设名称为“Amager Vest”,但目前只有“er Vest”可见。

在此处输入图像描述

You can increase border on the left:您可以增加左侧的边框:

plot.min_border_left = 15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM