import matplotlib.pyplot as plt
num_list=[1,5,6.5,8,11]
plt.bar(range(len(num_list)),num_list)
plt.title("zztu")
plt.xlabel("x")
plt.ylabel("y")
plt.show()
import matplotlib.pyplot as plt
num_list=[1,5,6.5,8,11]
plt.bar(range(len(num_list)),num_list,color='rgbcy')
plt.title("zztu")
plt.xlabel("x")
plt.ylabel("y")
plt.show()
import matplotlib.pyplot as plt
num_list=[1,5,6.5,8,11]
name_list=['Monday','Tuesday','Wednesday','Thursday','Friday']
plt.bar(range(len(num_list)),num_list,color='rgbcy',tick_label=name_list)
plt.title("zztu")
plt.xlabel("x")
plt.ylabel("y")
plt.show()
import matplotlib.pyplot as plt
num_list=[1,5,6,8,11]
num_list2=[2,3,5,1,4]
name_list=['Monday','Tuesday','Wednesday','Thursday','Friday']
plt.bar(range(len(num_list)),num_list,color='b',tick_label=name_list,label='boy')
plt.bar(range(len(num_list)),num_list2,color='g',tick_label=name_list,label='girl',bottom=num_list)
plt.title("zztu")
plt.xlabel("x")
plt.ylabel("y")
plt.legend(loc='best')#设置图例并且图例自动选择最佳位置
plt.show()
import matplotlib.pyplot as plt
num_list=[1,5,6,8,11]
num_list2=[2,3,5,1,4]
name_list=['Monday','Tuesday','Wednesday','Thursday','Friday']
plt.barh(range(len(num_list)),num_list,color='b',tick_label=name_list,label='boy')
plt.barh(range(len(num_list)),num_list2,color='g',tick_label=name_list,label='girl',left=num_list)
plt.title("zztu")
plt.xlabel("x")
plt.ylabel("y")
plt.legend(loc='best')#设置图例并且图例自动选择最佳位置
plt.show()
import matplotlib.pyplot as plt
num_list=[1,5,6,8,11]
num_list2=[2,3,5,1,4]
name_list=['Monday','Tuesday','Wednesday','Thursday','Friday']
x=list(range(len(num_list)))
total_width=0.8
n=2
width=total_width/n
plt.bar(x,num_list,label='boy',width=width)
for i in range(len(x)):
x[i]=x[i]+width
plt.bar(x,num_list2,tick_label=name_list,label='girl',width=width)
plt.title("zztu")
plt.xlabel("x")
plt.ylabel("y")
plt.legend(loc='best')#设置图例并且图例自动选择最佳位置
plt.show()
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']#正常显示中文,刚学到
labels='A','B','C','D'
sizes=[10,30,20,40]
plt.pie(sizes,labels=labels)
plt.title("饼状图")
plt.legend(loc='best')#设置图例并且图例自动选择最佳位置
plt.show()
explode参数,默认为0
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']#正常显示中文,刚学到
labels='A','B','C','D'
sizes=[10,30,20,40]
explode=(0,0.1,0.2,0.1)
plt.pie(sizes,labels=labels,explode=explode)
plt.title("饼状图")
plt.legend(loc='best')#设置图例并且图例自动选择最佳位置
plt.show()
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']#正常显示中文,刚学到
labels='A','B','C','D'
sizes=[10,30,20,40]
colors=['r','g','y','b']
plt.pie(sizes,labels=labels,colors=colors)
plt.title("饼状图")
plt.legend(loc='best')#设置图例并且图例自动选择最佳位置
plt.show()
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']#正常显示中文,刚学到
labels='A','B','C','D'
sizes=[10,30,20,40]
colors=['r','g','y','b']
plt.pie(sizes,labels=labels,colors=colors,autopct='%1.2f%%')
plt.title("饼状图")
plt.legend(loc='best')#设置图例并且图例自动选择最佳位置
plt.show()