如何在matplotlib,python中创建两个不同比例的子情节?

pcww981p  于 2022-12-13  发布在  Python
关注(0)|答案(1)|浏览(121)

我想在一个图中做两个(子)图,第一个我想在第二个线性-对数比例上做对数-对数比例。我怎么做呢?下面的代码不起作用。

figure, (ax1,ax2) = plt.subplots(1, 2)

plt.xscale("log")
plt.yscale("log")
ax1.plot(indices,pi_singal,linestyle='-')
plt.xscale("log")
plt.yscale("linear")
ax2.plot(indices,max_n_for_f)

plt.show()
e5nqia27

e5nqia271#

2个并排地块的示例

import matplotlib.pyplot as plt

# Create a figure with two subplots
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)

# Set the y-axis scale for the first subplot to linear
ax1.set_yscale("linear")

# Set the y-axis scale for the second subplot to log
ax2.set_yscale("log")

# Add data to the subplots
ax1.plot([1, 2, 3, 4], [1, 2, 3, 4])
ax2.plot([1, 2, 3, 4], [1, 2, 3, 4])

# Show the figure
plt.show()

相关问题