我有一个包含三列的pandas数据框:
scores weight x
0 5.000000 0.163265 bws
1 5.000000 0.163265 bwd
2 3.085501 0.020408 iav
3 1.208879 0.020408 sev
4 0.000000 0.040816 cfr
5 0.442407 0.040816 rfr
6 1.447025 0.081633 drr
7 NaN NaN gtd
8 0.634083 0.081633 ucw
9 1.233896 0.040816 cep
10 0.000000 0.081633 udw
11 0.000000 0.081633 usa
12 0.600000 0.020408 rri
目标是制作条形图。条形图应包含13条(每x个)。每个条的高度应基于分数。每个条的宽度应基于重量。理想情况下,条形图将彼此“接触”,因此很容易发现条形图的相对贡献。
Plotly的解决方案(那太好了,我需要与团队共享这些图表,并且plotly可以托管图表(共享URL))
import plotly.plotly as py
import plotly.graph_objs as go
data = [
go.Bar(
x=df['x'], # assign x as the dataframe column 'x'
y=df['scores'],
width=df["weight"]*10
)
]
layout = go.Layout(
barmode='stack',
bargap=0,
title='Stacked Bar with Pandas'
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='pandas-bar-chart-layout')
我尝试设置Bar和Layout对象的width和dx值,但是它们仅采用整数或浮点数。如何在数据框中的“重量”属性上设置每个熊的宽度?