Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplotlib 如何在pyplot中以对数比例绘制二次曲线_Matplotlib - Fatal编程技术网

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')