我需要画几张水平条形图。我应用了下面的for循环来绘制它们,但是我得到了一个错误
chart_cols = 'respondent_age respondent_gender respondent_edu respondent_occupation Religion Caste_cat CM_choice Likely_winner'.split()
for f in chart_cols:
count = df[f].value_counts()
p = figure(plot_height=400, plot_width=400, title='Chart',toolbar_location=None)
p.title.align = "right"
p.xaxis.axis_label = 'Number of respondents'
p.yaxis.axis_label = 'Something'
p.hbar(y=sorted(df[f].unique()), height=0.7, left=0,
right=count, color=Category20,
alpha=0.7)
show(p)
print('Done')
错误
^{pr2}$如何使用for循环绘制多个图表?文档中给出的示例显示了使用row
函数对2个绘图所做的相同操作。在
下面的代码现在可以工作了。 对于图表列中的f: count=df[f].value\u counts()
相关问题 更多 >
编程相关推荐