Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading