matplotlib绘图参数设置
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from scipy.interpolate import spline
x = np.arange(-5,11)
matplotlib中subploty = x**3 + 2*(x**2) + x + 2
y2 = 2*(x**3) + 2*(x**2) + x + 1
plt.figure(figsize=(10,6),facecolor='#ffffcc',edgecolor='#ffffcc') #绘图框的⼤⼩、颜⾊(放最前)
plt.subplot(111, facecolor='#e6e6e6')#绘图区,背景⾊(放在figure之后,绘图函数之前)
#绘图
plt.plot(x, y, color='red', linewidth=1, linestyle='--') #绘折现图
doc = plt.scatter(x, y2, color='green',label="绘点标签") #绘点图
#绘平滑曲线,将x轴上的点划分更多段来绘图
x_smooth = np.linspace(x.min(), x.max(), x.max()*1000)
y_smooth = spline(x, y2, x_smooth)
plt.plot(x_smooth, y_smooth, color='blue', linewidth=1,label="平滑线标签")
#其他设置
plt.xlim([-10,15]) #指X轴的显⽰范围
plt.ylim([-100,3000]) #指Y轴的显⽰范围
plt.title('标题', color='blue')
plt.xlabel('x 轴标签', color='blue')
plt.ylabel('y 轴标签', color='blue')
<((x.max()+x.min())/2,(y2.max()+y2.min())/2,'show text',ha='center')#图像上显⽰⽂本信息
for a,b in zip(x, y2): (a, b, str(b)) # 显⽰y值
plt.legend(loc=2)#图像标签说明,设置label的都显⽰(loc=2位于第⼆个⾓洛)
#plt.legend(handles=[doc], loc=2) #只显⽰⼀个图的标签
#icks((-4,-2,0,2,4,6,8,10),(-4,-2,0,2,4,6,8,10))#替换x轴刻度值
plt.axis('tight') #tight:坐标轴数据显⽰更明细(有不同选项)
plt.show() #显⽰图像