import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['KaiTi']#设置中文字体
plt.rcParams['axes.unicode_minus'] = False #取负数
#只含单一曲线
n = np.arange(10)
plt.plot(n)
#包含多个曲线
x = np.linspace(-1,1,100)
y = 1-x**2
plt.plot(x,y)
plt.plot(x,2*x+1)
plt.show() #显示绘制图,在show之前会画到一张图上
x = np.linspace(-10,10,100)
y = np.cos(x)
plt.plot(x,y)
plt.grid(c='g',alpha=0.5)#加网格
#添加网格线
plt.grid(True,lw=2,ls='--',c='red')#线宽、线风格、颜色
#画子图
x = np.linspace(-10,10,200)
y = np.cos(x)
fig = plt.figure(figsize=(10,6)) #画布大小(长,宽)
ax1 = fig.add_subplot(2,2,1) #前两个参数相乘说明共画子图数量,后面一个是画在哪个位置
ax1.plot(x,y)
ax2 = fig.add_subplot(2,2,2)
ax2.plot(x,2*y,c='red')#可以通过元组(R,G,B)设置颜色,还可以通过16进制设置颜色
ax3 = fig.add_subplot(2,2,3)
ax3.plot(x,4*y,c='g')
ax4 = fig.add_subplot(2,2,4)
ax4.plot(x,6*y,c&
matplotlib设置图的格式方法
最新推荐文章于 2022-07-31 18:04:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)