How to rotate the X axis labels in a bokeh shape?

I'm just starting to use Bokeh. Below I create some arguments that I use for rect figure .

x_length = var_results.index * 5.5 

Multiplying the index by 5.5 gave me more space between the labels.

 names = var_results.Feature.tolist() y_length = var_results.Variance y_center = var_results.Variance/2 

var_results is a Pandas framework that has a typical, sequential, non-repeating index. var_results also has a Features column, which is a string of non-duplicate names, and finally has a Variance column, which is a 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 essentially make a histogram with rectangles. Bokeh seems very customizable. But my schedule looks rough around the edges, literally.

enter image description here

As you can see, there is an ugly spot just below the chart and above the β€œFeatures” name. These are the names of the labels (technically the names of the rectangles). How do I create space and possibly rotate the labels 45 degrees so they are readable and not just overlapping clutter?

+6
source share
2 answers

To rotate tags, for example. 90 degrees to the left you can set major_label_orientation to Ο€ / 2. This can be done either when creating an axis element (like kwarg for an axis constructor if you use a low-level graph), or also after creating a graph / figure, for example:

 p.xaxis.major_label_orientation = math.pi/2 

See also this example in the documentation.

+11
source

As an alternative to rotation, you set the orientation to a fixed value :

 p.xaxis.major_label_orientation = "vertical" 

should do what you want.

+1
source

Source: https://habr.com/ru/post/1015127/


All Articles