【发布时间】:2020-07-28 07:00:39
【问题描述】:
我正在尝试将一个字符串变量添加到我的图表中,但我不知道如何将它放在栏中。 我的字符串变量叫做city。
ax.barh(df['date'].values, df['cases'].values, color= '#49cff3')
ax.text(0, 1.06, 'Number of Cases', transform=ax.transAxes, size=12, color='#777777')
ax.xaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,.0f}'))
ax.xaxis.set_ticks_position('top')
ax.tick_params(axis='x', colors='#777777', labelsize=12)
ax.set_yticks([])
ax.grid(which='major', axis='x', linestyle='-')
ax.set_axisbelow(True)
ax.text(0, 1.15, 'Total Number of cases',
transform=ax.transAxes, size=24, weight=600, ha='left', va='top')
plt.yticks()
plt.box(False)
这是我的输出
在此先感谢
【问题讨论】:
-
ax.set_yticks(range(len(df)));ax.set_yticklabels(df['city']) -
我尝试了这个解决方案,它产生了一个空图表,所有城市都捆绑在角落里;我将图片添加到原始问题中。感谢您的帮助
标签: python pandas numpy matplotlib jupyter-notebook