python怎么画excel里那种双y轴的图?类似这样的,左边和右边各一个纵轴
1个回答
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y1 = x ** 2
y2 = - x ** 3
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(x, y1, 'r-')
ax2.plot(x, y2, 'b-')
ax1.set_xlabel('X data')
ax1.set_ylabel('square of x', color='r')
ax2.set_ylabel('negative cube of x', color='b')
plt.title('double y-axes example')
plt.show()
赞
-
chaos0
2022-04-05 10:53