Geo*_*her 5 python matplotlib legend
我是python和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')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))
clr = ('blue', 'forestgreen', 'gold', 'red', 'purple')
h = plt.barh(y_pos, performance, xerr=error, align='center',
alpha=0.4, label=people, color=clr)
plt.yticks(y_pos, people)
plt.xlabel('Performance')
plt.title('How fast do you want to go today?')
plt.legend(handles=[h])
plt.show()
Run Code Online (Sandbox Code Playgroud)
但在传说中我只有一个元素.但我想要一个带有一个元素的图例,每个人都有一个菱形颜色的矩形.
谢谢.
Geosucher
| 归档时间: |
|
| 查看次数: |
1641 次 |
| 最近记录: |