29

When using the Plotly, I can set the title font in the layout part as follow.

titlefont=dict(size =14, color='black', family='Arial, sans-serif')

My question is How to set the font as Bold. Thanks

Jongware
  • 22,200
  • 8
  • 54
  • 100
Jason LiLy
  • 634
  • 2
  • 9
  • 19

3 Answers3

57

If you are using Python you can add the <b> html tag to the title attribute and you are good.

You can add some more limited HTML styling such as italic as well, see example below.

enter image description here

import plotly
plotly.offline.init_notebook_mode()
data = [plotly.graph_objs.Bar(
            x=['giraffes', 'orangutans', 'monkeys'],
            y=[20, 14, 23]
    )]
layout = go.Layout(title='<b>Bold</b> <i>animals</i>')

fig = plotly.graph_objs.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99
  • 8
    Although this solution works, I'm afraid it doesn't scale if I want to display multiple strings in bold format, such as -- Axes tick values. There has to be some other way in plotly to do this. – RodrikTheReader Jun 24 '20 at 06:55
5

One method for getting bold text is to change the font to Arial Black (or other bold font) which should be available on most systems. This method will scale a little easier to axes and other elements.

Here's the example with bold yaxes:

import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=['giraffes', 'orangutans', 'monkeys'],
            y=[20, 14, 23]))

fig.update_layout(title='animals')
fig.update_yaxes(tickfont_family="Arial Black")
fig.show()

enter image description here

jayveesea
  • 2,886
  • 13
  • 25
0

OP mentioned that the adding the tag doesn't scale if, for example, they have many strings that they want bolded. Perhaps if they had many x-axis tick values. If you want to bold all your x-axis tick labels, you could just insert the tags in a loop:

import plotly
import plotly.graph_objects as go

my_list = ['giraffes', 'orangutans', 'monkeys']
bold_items = []
for item in my_list:
    bold_items.append('<b>' + item + '</b>')

plotly.offline.init_notebook_mode()
data = [plotly.graph_objs.Bar(
            x=bold_items,
            y=[20, 14, 23]
    )]
layout = go.Layout(title='<b>Bold</b> <i>animals</i>')

fig = plotly.graph_objs.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)