11

Is there a way to adjust x_axis_label and y_axis_label font/font size in Bokeh (0.70)? I am aware of a way to adjust title font size with the title_text_font_size property, with:

figure (..., title_text_font_size="12pt")

Is there a way to then specify something like:

figure (..., x_axis_label_text_font_size='10pt')

(using the convention of <name>_text_font_size) to indicate the font size property. The above did not work. If this is not present, could someone give some pointers as to how to make this sort of adjustment in the cofeescript + API-side of things, so can contribute back to the project? Thanks

Jonathan Shore
  • 880
  • 2
  • 8
  • 21

2 Answers2

27

Figure exposes xaxis and yaxis attributes that you can use for that. In your use case it should be able to use:

p.xaxis.axis_label = 'whatever'
p.xaxis.axis_label_text_font_size = "40pt"

You can also adjust x and y labels simultaneously via the axis attribute:

p.axis.axis_label_text_font_style = 'bold'
joelostblom
  • 43,590
  • 17
  • 150
  • 159
Fabio Pliger
  • 686
  • 5
  • 5
  • good one! Just if someone has the same issue as myself. `p.xaxis.major_label_text_font_style = 'bold'` for categorical data – ReinholdN Jan 31 '20 at 03:59
0

This is how you can change the axis label using CustomJS:

p = figure(x_axis_label="Initial y-axis label",
           y_axis_label="Initial x-axis label")

# ...

# p.xaxis and p.yaxis are lists. To operate on actual the axes,
# we need to extract them from the lists first.
callback = CustomJS(args=dict(xaxis=p.xaxis[0],
                              yaxis=p.yaxis[0]), code="""
    xaxis.axis_label = "Updated x-axis label";
    yaxis.axis_label = "Updated y-axis label";
""")
tuomastik
  • 4,559
  • 5
  • 36
  • 48
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/13393070) – Uyghur Lives Matter Aug 19 '16 at 15:29
  • Sure. I will fix the answer. I thought it would have been a bad practice to copy and paste the same answer here since the question is the same as well after all. – tuomastik Aug 19 '16 at 15:47
  • It can be bad practice to just copy and paste the same answer because that can indicate the questions might be duplicates, and one should be closed as such. However, if the questions are merely similar, I would tailor the answers to each specific question. – Uyghur Lives Matter Aug 19 '16 at 15:50