1 柱形图
import numpy as np
import matplotlib.pyplot as plt
#准备数据
x=np.array(['baseketball','football','baseball','beautiful',])
y=np.array([10,20,20,9])
c=np.array(['#4CAF50','red','hotpink','#556B2F'])
#插入数据
plt.bar(x,y,color=c,width=0.5)
plt.title('hobby')
plt.show()
效果图
2.饼图
import numpy as np
import matplotlib.pyplot as plt
#准备数据
y=np.array([35,25,25,15])
l=['baseball','tennis','pingpong','others']
c=["#d5695d","#5d8ca8","#65a479","#a564c9"]
e=(0.1,0.2,0.2,0.3)
#插入数据
plt.pie(y,labels=l,colors=c,autopct='%.1f%%',explode=e)
plt.title('hobby')
plt.show()
效果图