使用旋转的垂直条形图='垂直'不工作

时间:2016-10-18 09:39:06

标签: python numpy matplotlib

来自matplot lib示例lines_bars_and_markers 使用rotation='vertical'不会使其垂直。我做错了什么?

"""
Simple demo of a horizontal bar chart.
"""
import matplotlib.pyplot as plt
plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt


# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)
plt.yticks(y_pos, people)
plt.xlabel('Performance')
plt.title('How fast do you want to go today?')

plt.show()
rotation='vertical'

1 个答案:

答案 0 :(得分:3)

barh用于水平条形图,更改为bar,然后交换轴的数据。你不能简单地写rotation='vertical',因为那不会告诉matplotlib库什么,它只是创建一个从未使用过的字符串。

import matplotlib.pyplot as plt
plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt


# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
x_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

plt.bar(x_pos, performance, yerr=error, align='center', alpha=0.4)
plt.xticks(x_pos, people)
plt.ylabel('Performance')
plt.title('How fast do you want to go today?')

plt.show()