Matplotlib-- data visualization plt.plot, plt.figure,

Data visualization functions plt.plot (x, y, ls, lw, c, marker, markersize, markeredgecolor, markerfacecolor, label)

And set the standard form of drawing a line
Parameters:
** X: ** abscissa; Y **: ** ordinate; LS or lineStyle **: ** line form ( '-', '-', ': 'and' - '); ** lw (or linewidth):. ** line width; ** c: ** color line; marker **: ** shape point line; ** markersize or ms: ** size marker, float; ** markerfacecolor: ** fill color point; ** markeredgecolor: tag edge color label: ** text label

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#使能够正常显示中文
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False

x=np.linspace(0,360,20) #建立20个从0到哦360的线性平均数据
y=np.sin(x/180*3.1415926)	#将x的角度值转换成弧度值
y1=np.sin(x/180*3.1415926)-2	#将x对应的y值整体向下平移2
plt.plot(x,y,c='red',lw=2,ls='-') #第一个红线:线宽为2,线性‘-’
#下面黑线,红点、黄轮廓的线
plt.plot(x,y1,c='black',lw=4,ls='-.',marker='o',\
         markersize=8,markerfacecolor='red',markeredgecolor='yellow',label='x和y对应的点和线')
plt.legend(loc='center') #显示标签位置
plt.show()

Here Insert Picture Description

The label of the display function, plt.legend (loc =)

Adjust the picture parameters plt.figure (figsize = (), dpi =, facecolor =)

** dpi: ** Resolution
** facecolor: ** picture background color

Title plt.title ()

The x-axis title plt.xlabel ()

y-axis title plt.ylabel ()

The x-axis range plt.xlim ()

y-axis range plt.ylim ()

The x-axis scale plt.xticks ()

The y-axis scale plt.yticks ()

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#使能够正常显示中文
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
x=np.linspace(0,720,40)
y=np.sin(x/180*3.1415926)-2
y1=np.sin(x/180*3.1415926)

plt.figure(figsize=[12.5,8.84],dpi=100,facecolor='orange')
plt.title('这是整幅图的标题')
plt.xlabel('x轴')
plt.ylabel('y轴')
plt.xticks(np.linspace(0,720,21))		#这里想要20段,但必须有21个标签
#plt.xlim([0,360])  未限制x轴显示
plt.plot(x,y1,c='black',lw=4,ls='-.',marker='o',\
         markersize=8,markerfacecolor='red',markeredgecolor='yellow',label='x和y1对应的点和线')
plt.legend(loc=0,fontsize='large',title='这是一个标题')
plt.show()	#第一次显示图片
plt.figure(figsize=[12.5,8.84],dpi=100,facecolor='orange')
plt.xticks(np.linspace(0,720,21))
plt.xlim([0,720])
plt.plot(x,y1,c='black',lw=4,ls='-.',marker='o',\
         markersize=8,markerfacecolor='red',markeredgecolor='yellow',label='x和y1对应的点和线')
plt.show()  #第二次显示图片

Here Insert Picture Description

Save plt.savefig ( 'path and name')

Pictures need to be saved using this command on a plt.show ()

Published 70 original articles · won praise 1 · views 2418

Guess you like

Origin blog.csdn.net/weixin_43794311/article/details/105014101