0

I know this question has been asked before (here, here, and the most comprehensive one) but none of the solutions worked for me.

My code:

from matplotlib import pyplot as plt
import numpy as np

fig, ax = plt.subplots(ncols=3)

c1 = plt.cm.Blues(np.linspace(0.3,0.9,4))
c2 = plt.cm.Greens(np.linspace(0.3,0.9,4))
c3 = plt.cm.Reds(np.linspace(0.3,0.9,4))
marker = 4*('<',) + 4*('o',) + 4*('s',)
line = 4*(':',) + 4*('--',) + 4*('-',)
colors = np.vstack((c1,c2,c3))

for val in range(11):

    if val < 4:
        c = 0
    elif (val >=4) & (val>7):

        c = 1

    else:
        c = 2
    x = np.array([1,2,3,4,5])
    y = x + x*val
    ax[c].plot(x,y,\
             color=colors[val], marker = marker[val],\
             linewidth=1,alpha=0.8)
    ax[c].set_xlim(0,10)
    ax[c].set_ylim(0,20)
    plt.setp(ax[c], aspect='equal', adjustable='box-forced')

    for tick in ax[c].xaxis.get_major_ticks():
        tick.label.set_rotation(45)

generates:

enter image description here

How can I set:

1) An equal aspect ratio

and if desired

2) Force the figure to remain its original width (by adjusting the height of the axis)

I have to mention that my figure size is set in a stylesheet.

Community
  • 1
  • 1
Moritz
  • 5,130
  • 10
  • 40
  • 81
  • Have you tried to set `plt.setp(..., aspect=1.0, adjustable='box-forced')`? – AGS Jul 13 '15 at 12:05
  • same result as with `'equal'` – Moritz Jul 13 '15 at 12:10
  • So setting `aspect=1` should achieve 1), right? So there is only 2) left unanswered? What is the *original width*? It seems that you refer to a resizing step (which I guess occurs when you set `aspect=1`). But why is that important? The figure that you posted seems to achieve what you want, no? – hitzg Jul 13 '15 at 13:16
  • No, it does give the same results as using `'equal'` – Moritz Jul 13 '15 at 14:20
  • 2
    your aspect ratio does look pretty equal to me. do you actually want square subplots and not an equal aspect ratio? – Achim Jul 13 '15 at 16:22

0 Answers0