0

I am trying to display a marker in the given plot. The plot is generating correctly. My question is regarding the legend shown in the image. Is it possible to show only one marker in the legend? Currently my code is displaying two markers in the legend.

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()

This is the legend:

Legend

zondo
  • 19,901
  • 8
  • 44
  • 83
nas
  • 2,289
  • 5
  • 32
  • 67

1 Answers1

0

Additionally to the options provided in this thread you can also set the number of points to appear in the legend as

import matplotlib.pyplot as plt
plt.rcParams['legend.numpoints'] = 1
Community
  • 1
  • 1
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712