如何在散景图中旋转X轴标签? [英] How to rotate X-axis labels in bokeh figure?
问题描述
I'm just starting to use Bokeh. Below I create some args I use for the rect figure.
x_length = var_results.index * 5.5
将索引乘以5.5可为标签之间留出更多空间.
Multiplying the index by 5.5 gave me more room between labels.
names = var_results.Feature.tolist()
y_length = var_results.Variance
y_center = var_results.Variance/2
var_results
是具有典型的,顺序的,非重复索引的Pandas数据框. var_results
还有一个列Features
,它是不重复的字符串,名称,最后它还有一个列Variance
,它是dtype float.
var_results
is a Pandas dataframe that has a typical, sequential, non-repeating index. var_results
also has a column Features
that is strings of non-repeated, names, and finally it has a column Variance
which is dtype float.
r = figure(x_range = names,
y_range = (-0.05,.3),
active_scroll = 'wheel_zoom',
x_axis_label = 'Features',
y_axis_label = 'Variance')
r.rect(x_length,
y_center,
width=1,
height=y_length,
color = "#ff1200")
output_notebook()
show(r)
我实质上是在制作带有矩形的条形图.散景似乎是非常可定制的.但是从字面上看,我的图看起来很粗糙.
I'm essentially making a bar chart with rectangles. Bokeh seems to be very customizable. But my graph looks rough around the edges, literally.
如您所见,图表下方和x轴标题功能"上方存在丑陋的污迹.这是标签标题(在技术上为矩形标题).如何为标签留出空间或将标签旋转45度,以使标签易于阅读而不仅仅是重叠的混乱?
As you can see there is an ugly smudge just below the chart and above the x-axis title 'Features'. This is the label titles (technically the rectangle titles). How do I create space for and perhaps rotate to 45 degrees the labels so that they are readable and not just an overlapping mess?
推荐答案
为了旋转标签,例如向左90度,可以将major_label_orientation
设置为π/2.这可以在创建轴元素时完成(如果使用低级绘图,则作为对轴构造函数的扭曲),也可以在创建绘图/图形后完成,例如:
In order to rotate the labels e.g. by 90 degrees to the left, you can set major_label_orientation
to π/2. This can be done either when creating the axis element (as a kwarg to the axis constructor if you are using low level plotting) or also after you have created a plot/figure, for instance by:
p.xaxis.major_label_orientation = math.pi/2
另请参见此示例在文档中.
这篇关于如何在散景图中旋转X轴标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!