我有一个numpy 2d数组想要在Ellipse Demo中显示它第一行是颜色,第二行是感觉的总和,第三行是
xz = np.array([['E6C637', '1692', 'well'],
['7EC31B', '1386', 'free'],
['595884', '1032', 'alone'],
['40B6B8', '905', 'comfortable'],
['99D013', '687', 'fine']])
在此代码内:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
NUM = 250
ells = [Ellipse(xy=np.random.rand(2) * 10,
width=np.random.rand(), height=np.random.rand(),
angle=np.random.rand() * 360)
for i in range(NUM)]
fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
for e in ells:
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_alpha(np.random.rand())
e.set_facecolor(np.random.rand(3))
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
plt.show()
以下代码将给定的数据显示为pie chart:
import matplotlib.pyplot as plt
import numpy as np
xz = [['E6C637', '1692', 'well'],
['7EC31B', '1386', 'free'],
['595884', '1032', 'alone'],
['40B6B8', '905', 'comfortable'],
['99D013', '687', 'fine']]
labels = [data[2] for data in xz]
sizes = [float(data[1]) for data in xz]
colors = ['#'+data[0] for data in xz]
fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, colors=colors,
autopct='%1.1f%%', startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
# plt.legend() # show a legend
plt.show()