Matplotlib 如何在pyplot中以对数比例绘制二次曲线
我想有两条线(或更好的散点图)在一个绘图Matplotlib 如何在pyplot中以对数比例绘制二次曲线,matplotlib,Matplotlib,我想有两条线(或更好的散点图)在一个绘图 次级Y线应为对数刻度。如何使用python matplotlib执行此操作?您可以使用ax2=ax.twinx()创建第二个y轴。然后,正如塔卡斯韦尔在评论中指出的那样,可以将第二个轴设置为对数刻度 import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(5,3)) ax = fig.add_subplot(111) ax2 = ax.twinx() x
次级Y线应为对数刻度。如何使用python matplotlib执行此操作?您可以使用
ax2=ax.twinx()
创建第二个y轴。然后,正如塔卡斯韦尔在评论中指出的那样,可以将第二个轴设置为对数刻度
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(5,3))
ax = fig.add_subplot(111)
ax2 = ax.twinx()
x = np.random.rand(10)
y = np.random.rand(10)
y2 = np.random.randint(1,10000, size=10)
l1 = ax.scatter(x,y, c="b", label="lin")
l2 = ax2.scatter(x,y2, c="r", label="log")
ax2.set_yscale("log")
ax2.legend(handles=[l1, l2])
ax.set_ylabel("Linear axis")
ax2.set_ylabel("Logarithmic axis")
plt.tight_layout()
plt.show()
ax2.set_yscale('log')
?