以下是我生成条形图的Python代码:
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
objects = ('Increasing operational efficiency',
'Informing strategic direction',
'Better customer service',
'Identifying and developing new products',
'Enhanced customer experience',
'Identifying new markets',
'Faster go to market',
'Complying with regulations',
'Other')
y_pos = np.arange(len(objects))
performance = [51, 36, 27, 24, 20, 11, 8, 6, 3]
plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.show()
在输出中xticks正在重叠,有没有办法克服它。我的第二个疑问是在yticks中值为0到60,间隔为10,是否有任何方法可以添加'%'符号以及0%,10%,...,60%等数字比0,10,...,60。
感谢您的帮助,我是mathplotlib的新手
答案 0 :(得分:2)
您可以通过简单的搜索找到问题的答案......
您可以使用plt.gcf().autofmt_xdate()
对于y轴上的百分号,请使用
ax = plt.gca()
vals = ax.get_yticks()
ax.set_yticklabels(['{:.0f}%'.format(x) for x in vals])