physically stretch plot in horizontal direction in python
Question:
I want a simple x,y plot created with matplotlib stretched physically in x-direction.
The intention is to get a result were it is easier for me to detect features in the signal.
So I don’t want to change any scales or values or limits. Just change the distance between two gridpoint in my output file…
I want to do that on four subplots which should have the same size afterwards.
Thanks in advance… I tried for hours now and I think one of you could probably help me…
David Zwicker already solved my problem in this special case, thanks a lot for that, but in general… If I plot 2 subplots like in this code:
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
plot(u_av,z)
ax2 = fig.add_subplot(1,2,2)
plot(pgrd_av,z)
clf()
and want to stretch only one of them. What can I do?
Answers:
You can change the figure size by using plt.figure(figsize=(20,5))
. See the documentation of the figure command.
You can directly add axes to the canvas at an arbitrary position with plt.axes()
. For instance:
ax1 = plt.axes([0, 0, 3, 0.5])
ax2 = plt.axes([0, 0.6, 1, 1])
You can do this:
x = 1.5 # or your needed amount
plt.plot(x_array * x, y_array)
Your line or graph will move to the right depending on your x value
I want a simple x,y plot created with matplotlib stretched physically in x-direction.
The intention is to get a result were it is easier for me to detect features in the signal.
So I don’t want to change any scales or values or limits. Just change the distance between two gridpoint in my output file…
I want to do that on four subplots which should have the same size afterwards.
Thanks in advance… I tried for hours now and I think one of you could probably help me…
David Zwicker already solved my problem in this special case, thanks a lot for that, but in general… If I plot 2 subplots like in this code:
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
plot(u_av,z)
ax2 = fig.add_subplot(1,2,2)
plot(pgrd_av,z)
clf()
and want to stretch only one of them. What can I do?
You can change the figure size by using plt.figure(figsize=(20,5))
. See the documentation of the figure command.
You can directly add axes to the canvas at an arbitrary position with plt.axes()
. For instance:
ax1 = plt.axes([0, 0, 3, 0.5])
ax2 = plt.axes([0, 0.6, 1, 1])
You can do this:
x = 1.5 # or your needed amount
plt.plot(x_array * x, y_array)
Your line or graph will move to the right depending on your x value