当前位置:网站首页>Matplotlib line chart, text display, win10

Matplotlib line chart, text display, win10

2022-06-26 03:54:00 starmultiple

matplotlib

matplotlib: One of the most popular Python Bottom drawing library , Mainly for data visualization chart , The name comes from MATLAB, imitation MATLAB structure

from matplotlib import pyplot as plt# Import pyplot

#figure Represents a graphic icon 
#dpi It refers to the number of pixels per inch 
x=range(2,26,2)
# Definition x Axis 2~24 In steps of 2
y=[14,13,14.5,17,2,23,25,26,24,22,18,15]
# Set picture size 
fig =plt.figure(figsize=(20,8),dpi=80)
# mapping 
plt.plot(x,y)

# draw x The axis scale cannot be used directly here 0.5 The step size is therefore defined as follows 
_xtick_labels=[i/2 for i in range(4,49)]
plt.xticks(range(2,27))
plt.xticks(range(min(y),max(y)+1))
# Save the picture 
plt.savefig("./sig_size.png")# Can be saved as svg This vector graph format , Zoom in without jagging 
plt.show()

 Insert picture description here

problem :
If the list a Express 10 Point to 12 The temperature of every minute of the hour , How to draw a line chart to observe the change of temperature every minute ?
a=[random.randlint(20,35) for i in range(120)]

from matplotlib import pyplot as plt
import random# Random function 
x=range(0,120)
y=[random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
# adjustment x Axis scale 
_x=list(x)
_xtick_labels=["10 spot {} branch ".format(i) for i in range(60)]
_xtick_labels+=["11 spot {} branch ".format(i) for i in range(60)]
# Step size 
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45)#rotation=45 rotate 45°

plt.show()

 Insert picture description here
Set Chinese display
 Insert picture description here Law 1 :( recommend )

from matplotlib import pyplot as plt
import random# Random function 
#!! Just this line 
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
x=range(0,120)
y=[random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
# adjustment x Axis scale 
_x=list(x)
_xtick_labels=["10 spot {} branch ".format(i) for i in range(60)]
_xtick_labels+=["11 spot {} branch ".format(i) for i in range(60)]
# Step size 
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45) #rotation=45 rotate 45°
# Add a description 
plt.xlabel(' Time ')
plt.ylabel(' temperature : Company (℃)')
plt.title(' Temperature change from ten to twelve ')
plt.show()

Law two :

from matplotlib import pyplot as plt
import random# Random function 
from matplotlib import font_manager
# Another way to set the font 
my_font=font_manager.FontProperties(fname='C:\WINDOWS\FONTS\MSYHL.TTC')
x=range(0,120)
y=[random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
# adjustment x Axis scale 
_x=list(x)
_xtick_labels=["10 spot {} branch ".format(i) for i in range(60)]
_xtick_labels+=["11 spot {} branch ".format(i) for i in range(60)]
# Step size 
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45,fontproperties=my_font)#rotation=45 rotate 45°
# Add a description 
plt.xlabel(" Time ",fontproperties=my_font)
plt.ylabel(" temperature   Company (℃)",fontproperties=my_font)
plt.title("10 Point to 12 Temperature changes per minute at the point ",fontproperties=my_font)
plt.show()

 Insert picture description here

原网站

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