python plotly画柱状图

代码

import pandas as pd
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go

path = ‘/home/v-gazh/PycharmProjects/us_data/counts.csv‘

df = pd.read_csv(path)
df[‘PERMNO‘] = df[‘PERMNO‘].map(lambda x : ‘P‘+str(x) )  # 该了下类型 此行有可无
df.set_index([‘PERMNO‘], inplace=True)

 
trace1 = go.Bar(
    x=df.index,
    y=df[‘tickerCount‘].squeeze(),
    name=‘一个P对应TICKER个数‘
)
trace2 = go.Bar(
    x=df.index,
    y=df[‘exchcdCount‘].squeeze(),
    name=‘一个P对应EXCHCD个数‘
)
 
data = [trace1, trace2]
layout = go.Layout(
    barmode=‘group‘#分组
)
 
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename=‘grouped-bar‘)

图示

python plotly画柱状图

 python plotly画柱状图

相关推荐