19

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?

askewchan
  • 45,161
  • 17
  • 118
  • 134
Bachbold
  • 424
  • 1
  • 6
  • 14

4 Answers4

17

You can change the figure size by using plt.figure(figsize=(20,5)). See the documentation of the figure command.

David Zwicker
  • 23,581
  • 6
  • 62
  • 77
  • 1
    ok that changes the size of my whole figure but what can I do if I wanted to adjust only one subplot? Is anything similar available for the subplot function? – Bachbold Dec 05 '13 at 13:02
  • Your question is not very clear. Maybe you can post some example code and/or example images? This would certainly clarify your request. Generally, you can places axes any way you want. The axes_grid helpers are useful here, e.g. http://matplotlib.org/1.3.0/examples/axes_grid/make_room_for_ylabel_using_axesgrid.html – David Zwicker Dec 05 '13 at 13:17
10

I know, this is a bit out of the context. But if someone is looking for a solution while using pandas plot which internally uses matplotlib. Here is the solution.

df.plot('col_x', 'col_y', title='stretched_plot', figsize=(20, 1))

enter image description here

Jyotirmay
  • 1,533
  • 3
  • 21
  • 41
4

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

Arbitrary axes

jmz
  • 4,138
  • 28
  • 27
  • 3
    I have exactly this problem but callings plt.axes() only deforms the location of my xlabel/ylabel/title. Meanwhile the neither the x or y axes are stretched. – Max Mar 28 '16 at 15:48
  • ^ same w colorbar. This doesn't work if you have some other elements besides the ax. – gannonbarnett Dec 01 '21 at 06:35
0

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