当前位置:网站首页>Matplotlib multi line chart, dot scatter chart

Matplotlib multi line chart, dot scatter chart

2022-06-26 03:54:00 starmultiple

matplotlib Line chart scatter chart
Single polyline

# coding=utf-8
from matplotlib import pyplot as plt

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(11,31)
y=[1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
# Set graphic size 
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)# draw xy
# Set up x Axis scale 
_xtick_labels=["{} year ".format(i) for i in x]
plt.xticks(x,_xtick_labels)
plt.yticks(range(0,9))
# Draw mesh 
plt.grid(alpha=0.2)# transparency 
# Exhibition 
plt.show()

 Insert picture description here
Polygonal line

# coding=utf-8
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(11,31)
y1=[1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y2=[1,0,3,1,2,2,3,3,2,1,2,1,1,1,1,1,1,1,1,1]
# Set graphic size 
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y1,label="y1")# draw xy
plt.plot(x,y2,label="y2")
# Set up x Axis scale 
_xtick_labels=["{} year ".format(i) for i in x]
plt.xticks(x,_xtick_labels)
plt.yticks(range(0,9))
# Draw mesh 
plt.grid(alpha=0.2)# transparency 

# Add legend 
plt.legend()
# Exhibition 
plt.show()

 Insert picture description here Enrich

# coding=utf-8
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(11,31)
y1=[1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y2=[1,0,3,1,2,2,3,3,2,1,2,1,1,1,1,1,1,1,1,1]
# Set graphic size 
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y1,label="y1",color="orange",linestyle=':',linewidth=10)# draw xy
plt.plot(x,y2,label="y2",color="cyan",linestyle='--',linewidth=5)
# color Color  linestyle Line style  linewidth Line width 
# Set up x Axis scale 
_xtick_labels=["{} year ".format(i) for i in x]
plt.xticks(x,_xtick_labels)
plt.yticks(range(0,9))
# Draw mesh 
plt.grid(alpha=0.2)# transparency 

# Add legend , Place the legend on the left 
plt.legend(loc="upper left")
# Exhibition 
plt.show()

 Insert picture description here Electric scatter diagram
The law of temperature and weather change

from matplotlib import pyplot as plt

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
y_a=[11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,23]
y_b=[26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,5,13,17,10,11,13,12,13,6]

x_a=range(1,30)
x_b=range(41,71)
# Set graphic size 
plt.figure(figsize=(20,8),dpi=80)

plt.scatter(x_a,y_a,label=" March ")
plt.scatter(x_b,y_b,label="10 month ")
# adjustment x Axis scale 
_x=list(x_a)+list(x_b)
_xtick_labels=["3 month {} Japan ".format(i) for i in x_a]
_xtick_labels+=["10 month {} Japan ".format(i-50) for i in x_b]
plt.xticks(_x[::1],_xtick_labels[::1],rotation=45)
# Add legend 
plt.legend(loc="upper left")

# Add a description 
plt.xlabel(" Time ")
plt.ylabel(" temperature ")
plt.title(" title ")


plt.show()

 Insert picture description here

原网站

版权声明
本文为[starmultiple]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260344540560.html