Geosucher
Geosucher

Reputation: 107

Wedges with label parameter, but none label in result

I am beginner with python (3.4) and matplotlib. I want to create a wedge with the following code:

import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig1 = plt.figure()
ax1 = fig1.add_subplot(111, aspect='equal')
ax1.add_patch(patches.Wedge(center=(0,0), r=0.9, theta1=90, theta2=120, facecolor="red", label="Test"))
plt.xlim(-1, 1)
plt.ylim(-1, 1)
fig1.savefig('wedge1.png', dpi=90, bbox_inches='tight')
plt.show()

All Looks fine, but the Label isn't in the plot? Any idea?

Chart with no Label???

Upvotes: 1

Views: 286

Answers (1)

Imanol Luengo
Imanol Luengo

Reputation: 15909

You are missing a plt.legend(). You just need to add it anywhere before the plt.show (also before fig1.savefig if you want it saved in the image) and after all your plots:

import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig1 = plt.figure()
ax1 = fig1.add_subplot(111, aspect='equal')
ax1.add_patch(patches.Wedge(center=(0,0), r=0.9, theta1=90, theta2=120, facecolor="red", label="Test"))
plt.xlim(-1, 1)
plt.ylim(-1, 1)
plt.legend()  # <--- here
fig1.savefig('wedge1.png', dpi=90, bbox_inches='tight')
plt.show()

enter image description here

Have a look here for further details on how to use legends.

Upvotes: 1

Related Questions