Home > OS >  How do I make two subplots with diffrent scales in matplotlib, python?
How do I make two subplots with diffrent scales in matplotlib, python?

Time:12-13

I wanna make two (sub) plots in one figure, on the first I wanna have log-log scale on second linear-log scale. How do I do that? Following code doesn't work.

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

CodePudding user response:

example of 2 plots side by side

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

enter image description here

  • Related