Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aesthetics Plotly - Title in the offline mode

I have a basic question, tried many variations and couldn´t get it right. I am trying to put a title in a plotly barchart printes offline in a jupyter notebook. I am using python.

Without the title I can get the graph ok:

from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()
import plotly.graph_objs as go

trace_2 = go.Bar(x=['Jan','Feb','Mar'],
              y = [1,2,3],
               text = [1,2,3],
               textposition = 'auto',
                   marker=dict(
                    color='rgb(158,202,225)'),)
data_2 = [trace_2]               


fig_2 = go.Figure(data=data_2)


iplot(fig_2)

When I try to put the title in, as in the tutorial, I get a lot of unexpected errors. How can I put the title "Count of the month" on top of the Graph?

tks

like image 788
user1922364 Avatar asked Oct 30 '25 04:10

user1922364


1 Answers

You need to use the title property of layout object, which you then pass to fig object, please refer the below example. Also please checkout the official docs for `plotly layout title.

from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()
import plotly.graph_objs as go

trace_2 = go.Bar(x=['Jan','Feb','Mar'],
              y = [1,2,3],
               text = [1,2,3],
               textposition = 'auto',
                   marker=dict(
                    color='rgb(158,202,225)'),)
data_2 = [trace_2]               
layout = {'title': 'Count of the month'}

fig_2 = go.Figure(data=data_2, layout = layout )


iplot(fig_2)
like image 78
Naren Murali Avatar answered Nov 02 '25 19:11

Naren Murali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!