Python:(使用matplotlib画图)次坐标轴,两个坐标轴

 

 

代码如下

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0,10,0.1)

y1 = 0.05 * x**2
y2 = -1 * y1

fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
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()

 

相关文章:

  • 2021-06-17
  • 2021-06-22
  • 2022-01-17
  • 2021-09-10
  • 2021-06-13
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2022-01-21
  • 2021-11-17
  • 2022-12-23
  • 2021-09-16
相关资源
相似解决方案