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

Question:

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()
Asked By: Von

||

Answers:

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

Answered By: tomerar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.