Reputation: 1227
When plotting a graph with Plotly, is there a way to set a font for the whole figure at once (so that you don't have to set it individually for each element in your graph)?
For MatPlotLib this is done with:
matplotlib.pyplot.rcparams["font.family"] = "Calibri"
For Plotly this is done with:
?????
Upvotes: 4
Views: 6495
Reputation: 9148
That can be done editing templates:
import plotly.io as pio
import plotly.graph_objects as go
pio.templates["my_modification"] = go.layout.Template(
layout=dict(font={"size": 20})
)
# Then combine your modification with any of the
# available themes like this:
pio.templates.default = "plotly_white+my_modification"
Upvotes: 2
Reputation: 5992
If you have a font (or any style really) that you want to apply to many figures
import plotly.figure_factory as ff
class Plot():
def __init__(self):
self.my_template = dict(
layout=go.Layout(
font=dict(family='Arial')
)
)
def some_plot(self):
#fig = ...
fig.update_layout(template=self.my_template)
return fig
Upvotes: 2
Reputation: 27370
You should be able to do this with e.g.fig.layout.font.family = 'Arial'
This will be used as the default for all other fig.<anything>.font.family
unless you explicitly override them.
Here is the documentation link: https://plot.ly/python/reference/#layout-font-family
If you want this set Plotly-wise you can use a Template: https://plot.ly/python/templates/
Upvotes: 5