Reputation: 31
Is matplotlib
capable of creating semicircle charts like this:
I have tried matplotlib.pyplot.pie
without success.
Upvotes: 1
Views: 4996
Reputation: 31
My solution:
import matplotlib.pyplot as plt
# data
label = ["A", "B", "C"]
val = [1,2,3]
# append data and assign color
label.append("")
val.append(sum(val)) # 50% blank
colors = ['red', 'blue', 'green', 'k']
# plot
plt.figure(figsize=(8,6),dpi=100)
wedges, labels=plt.pie(val, wedgeprops=dict(width=0.4,edgecolor='w'),labels=label, colors=colors)
# I tried this method
wedges[-1].set_visible(False)
plt.show()
Output: enter image description here
Upvotes: 1
Reputation: 4648
It doesn't seem like there is a built-in half-circle type in matplotlib
. However, a workaround can be made based on matplotlib.pyplot.pie
:
Sample Code:
import matplotlib.pyplot as plt
# data
label = ["A", "B", "C"]
val = [1,2,3]
# append data and assign color
label.append("")
val.append(sum(val)) # 50% blank
colors = ['red', 'blue', 'green', 'white']
# plot
fig = plt.figure(figsize=(8,6),dpi=100)
ax = fig.add_subplot(1,1,1)
ax.pie(val, labels=label, colors=colors)
ax.add_artist(plt.Circle((0, 0), 0.6, color='white'))
fig.show()
Output:
Upvotes: 2