막대그래프
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.rand(10, 2), columns=['A', 'B'])
df.head()
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(
go.Bar(
x=df.index, y=df['A'], name='A', text=df['A'], textposition='auto'
)
)
fig.add_trace(
go.Bar(
x=df.index, y=df['B'], name='B', text=df['B'], textposition='auto'
)
)
fig.show()
그래프 세부 조정
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(
go.Bar(
x=df.index, y=df['B'], name='A', text=df['B'], textposition='auto', texttemplate='%{y:.2f}'
)
)
fig.add_trace(
go.Bar(
x=df.index, y=df['A'], name='B', text=df['A'], textposition='auto', texttemplate='%{y:.2f}'
)
)
fig.update_layout(
{
"title": {
"text": "Graph with <b>go.Bar</b>",
"x": 0.5,
"y": 0.9,
"font": {
"size": 20
}
},
"showlegend": True,
"xaxis": {
"title": "random number",
"showticklabels":True,
"dtick": 1
},
"yaxis": {
"title": "A"
},
"autosize":False,
"width":800,
"height":340
}
)
fig.show()