On a standard Bokeh line graph, the color of y-axis label text can be set with the code:
graph.yaxis.major_label_text_color = "#1F77B4"
It is possible to add a second y-axis to the graph, yielding twin axes. The following code would achieve this:
graph.extra_y_ranges = {"range2": bokeh.models.Range1d(start = 0, end = 500)}
graph.add_layout(bokeh.models.LinearAxis(y_range_name = "range2"), "left")
However, it's not clear how to change the color of the label text for this second y-axis. The first code block doesn't specify which y-axis, but it affects the original one. It would be nice if the color of each set of labels corresponded to the lines they measured. How can the color of the new y-axis be changed?
The attributes such as p.xaxis
and p.yaxis
are actually lists:
In [41]: p.add_layout(LinearAxis(y_range_name="foo"), 'left')
In [42]: p.yaxis
Out[42]:
[LinearAxis(id='c9d9c010-3698-4906-83b0-e8a9a244e4be', ...),
LinearAxis(id='c991b6b3-e85a-4033-b028-4e2ee134df1c', ...)]
However, because the vastly more common case is to have a single axis, it was made possible to do this:
p.yaxis.major_label_text_color = "red"
as a convenience. This will set the property value for all y axes present. But of you just want to change one, instead of all of them, you can always be explicit by indexing:
p.yaxis[1].major_label_text_color = "red"
For reference, this is all documented in the User's Guide chapter Styling Visual Attributes
And as a reminder the styling for any additional axis needs to be applied after the p.add_layout(LinearAxis())
creates the object.