我正在尝试使用MatPlotLib在条形图上绘制线图。到目前为止,我已经显示了这两个图,但我不能得到一个不同比例的二次y轴来工作。当我试着把另一个放进去时,会覆盖原来的比例。我的代码如下
def hridef_base(x):
if x == 1:
deltatlapexit = ExitSummary['Avg tLap'] - ExitSummary2['Avg tLap']
plt.figure()
index = (EntrySummary.index + 1)
barwidth = 0.2
plt.ylim(0.0, 65.0)
plt.bar(index-barwidth, EntrySummary['Avg FRH'], barwidth, color='r', yerr=EntrySummary['FRH StDev'], ecolor='k', label='Entry')
plt.bar(index, ApexSummary['Avg FRH'], barwidth, color='#4169E1', yerr=ApexSummary['FRH StDev'], ecolor='k', label='Apex')
plt.bar(index+barwidth, ExitSummary['Avg FRH'], barwidth, color='#32CD32', yerr=ExitSummary['FRH StDev'], ecolor='k', label='Exit')
plt.plot(index, deltatlapexit, color='k', label='Entry')
plt.xlabel('Turn Number')
plt.ylabel('Average FRideH')
plt.title('Average FRideH for Baseline setup')
plt.xticks(index)
plt.legend()
else:
print "Baseline FRideH Not Selected"
任何关于这件事的建议都很感激,但请告诉我该怎么做,而不是发布到网站的链接。我要明白为什么我不能这么做。
提前谢谢你。如果我漏掉了什么,请评论。
由于下面的注释,该图现在有两个独立的y轴。条形数据的y标签是如何跳到右边的,如果我尝试绘制y标签线,就会得到一个属性错误。
def hridef_base(x):
if x == 1:
deltatlapexit = ExitSummary['Avg tLap'] - ExitSummary2['Avg tLap']
fig, axis1 = subplots()
index = (EntrySummary.index + 1)
barwidth = 0.2
axis1.ylim(0.0, 65.0)
axis1.bar(index-barwidth, EntrySummary['Avg FRH'], barwidth, color='r', yerr=EntrySummary['FRH StDev'], ecolor='k', label='Entry')
axis1.bar(index, ApexSummary['Avg FRH'], barwidth, color='#4169E1', yerr=ApexSummary['FRH StDev'], ecolor='k', label='Apex')
axis1.bar(index+barwidth, ExitSummary['Avg FRH'], barwidth, color='#32CD32', yerr=ExitSummary['FRH StDev'], ecolor='k', label='Exit')
axis2 = axis1.twinx()
axis2.set_ylim(-10.0, 10.0)
axis2.plot(index, deltatlapexit, color='k', label='tDelta')
axis1.xlabel('Turn Number')
axis1.ylabel('Average FRideH')
axis2.set_ylabel('tDelta')
axis1.title('Average FRideH for Baseline setup')
axis1.xticks(index)
axis1.legend()
axis2.legend()
else:
print "Baseline FRideH Not Selected"
我会插入一个图像,但我需要10个代表点。。。
我收到的错误是: 名称错误:未定义全局名称“子块”
我没有您的数据,但是使用matplotlib中的barplot example,下面是一个条形图和线图重叠的示例,它们具有独立缩放的y轴:
从matplotlib导入pyplot作为plt 将numpy导入为np
作为基于this的最简单的例子
这给了我们,
相关问题 更多 >
编程相关推荐