matplotlib:次坐标轴ax2=ax1.twinx()

import numpy as np
import matplotlib
matplotlib.use(“TkAgg”)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.gridspec as gridspec

x=np.arange(0,10,0.1)
y1=0.05x**2
y2=-1
y1

fig,ax1=plt.subplots()
ax2=ax1.twinx()#产生一个ax1的镜面坐标
ax1.plot(x,y1,“g-”)
ax2.plot(x,y2,“b–”)

ax1.set_xlabel(“X data”)
ax1.set_ylabel(“Y1”,color=“g”)
ax2.set_ylabel(“Y2”,color=“b”)

plt.show()
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43055882/article/details/86518802