plotly绘制简单图形--金字塔图

为了参照对比,我们一般需要画类似金字塔形状的图表来展示数据,

下面我们那一个例子来看一下效果

import plotly.plotly as py
import plotly.graph_objs as go

import numpy as np

women_bins = np.array([-600, -623, -653, -650, -670, -578, -541, -411, -322, -230])
men_bins = np.array([600, 623, 653, 650, 670, 578, 541, 360, 312, 170])

y = list(range(0, 100, 10))

layout = go.Layout(yaxis=go.layout.YAxis(title='Age'),
                   xaxis=go.layout.XAxis(
                       range=[-1200, 1200],
                       tickvals=[-1000, -700, -300, 0, 300, 700, 1000],
                       ticktext=[1000, 700, 300, 0, 300, 700, 1000],
                       title='Number'),
                   barmode='overlay',
                   bargap=0.1)

data = [go.Bar(y=y,
               x=men_bins,
               orientation='h',#水平条形图需设置,竖直条形图不用设置
               name='Men',
               hoverinfo='x',
               marker=dict(color='#808080')#设置颜色
               ),
        go.Bar(y=y,
               x=women_bins,
               orientation='h',#水平条形图需设置,竖直条形图不用设置
               name='Women',
               text=-1 * women_bins.astype('int'),#women的数据标签
               hoverinfo='text',
               marker=dict(color='seagreen')
               )]

py.iplot(dict(data=data, layout=layout)) 

 

plotly绘制简单图形--金字塔图_第1张图片 

你可能感兴趣的:(数据可视化)