Skip to content Skip to sidebar Skip to footer

Plotly: How To Format Text (underline, Bold, Italic)

I try to underline text in plotly when using annotations. I add my annotations using import plotly.graph_objects as go g = go.FigureWidget(make_subplots(rows=1,cols=1)) g.update_l

Solution 1:

Plotly uses a subset of HTML tags to format text like bold '<b></b>' and italics '<i></i>'. Alas, '<u></u>' does not seem to be included at the moment. But linebreak is included, so you could make a little work-around like this:

string = "These are orange"
myText = string+'<br>'+ '-'*len(string)

Plot:

enter image description here

Code:

import plotly.graph_objects as go
animals=['giraffes', 'orangutans', 'monkeys']

fig = go.Figure([go.Bar(x=animals, y=[20, 14, 23])])

string = "These are orange"
myText = string+'<br>'+ '-'*len(string)

fig.update_layout(annotations=[dict(x='orangutans',y = 15, text=myText, font=dict(family='Courier New, monospace'))])
fig.show()

Plotly source: using help(fig.layout):

  text
 |                  Sets the text associated with this annotation.
 |                  Plotly uses a subset of HTML tags to do things
 |                  like newline (<br>), bold (<b></b>), italics
 |                  (<i></i>), hyperlinks (<a href='...'></a>).
 |                  Tags <em>, <sup>, <sub> <span> are also
 |                  supported.

Post a Comment for "Plotly: How To Format Text (underline, Bold, Italic)"