我正在尝试在给定的情节中显示标记。情节正确生成。我的问题是关于图像中显示的图例。是否可以在图例中仅显示一个标记?目前我的代码在图例中显示两个标记。
import matplotlib.pyplot as plt
X = [590,540,740,130,810,300,320,230,470,620,770,250]
Y = [32,36,39,52,61,72,77,75,68,57,48,48]
fig = plt.figure()
ax = plt.subplot(111)
line, = ax.plot(X, Y, 'ro', marker='^', label="Relationship Between Temperature and Iced Coffee Sales", markersize='10')
plt.xlim(0,1000)
plt.ylim(0,100)
plt.title('Relationship Between Temperature and Iced Coffee Sales')
plt.xlabel('Cups of Iced Coffee Sold')
plt.ylabel('Temperature in Fahrenheit')
box = ax.get_position()
ax.set_position([box.x0, box.y0 + box.height * 0.1,
box.width, box.height * 0.9])
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
fancybox=True, shadow=True, ncol=5)
plt.show()
这是传说:
答案 0 :(得分:0)
除this thread中提供的选项外 您还可以将图例中显示的点数设置为
import matplotlib.pyplot as plt
plt.rcParams['legend.numpoints'] = 1