0

I'm having some issues with matplotlib in Python 2.7. Basically, I'm trying to graph some values (Y) against a corresponding X value. What happens is I get a completely squished x-axis.

I have a variable, Xmse that has the following value:

Xmse = [2028.5457074044693,
 1653.3262637440594,
 1337.3889339729938,
 1176.2728864230257,
 1072.2873906521645,
 981.65920843213678,
 912.14636955892638,
 858.67713877925848,
 807.43207831735913,
 764.48689721143887]

Each value is calculated based on a boundary: boundary = [1,2,3,4,5,6,7,8,9,10].

So when I try to plot the graph where boundary is my x-value and Xmse is my Y value, I get this plot:

squished plot

from this code:

plt.plot(boundary,Xmse)
plt.show()

So it seems like my y-values are almost inverted and for some reason I have a negative value on the y pat even though none of my values are negative. Also, the x-axis is squished. After looking online, I tried to add the following to my code:

plt.xticks([1,2,3,4,5,6,7,8,9,10])
plt.plot(boundary,Xmse)
plt.show()

But I still end up with the same plot. So how can I just graph a simple line which corresponds to an X-Y value in matplotlib?

Alex
  • 2,145
  • 6
  • 36
  • 72
  • Read up on the aspect ratio or see this answer: `http://stackoverflow.com/questions/7965743/how-can-i-set-the-aspect-ratio-in-matplotlib` – roadrunner66 Mar 11 '16 at 07:15

1 Answers1

0

This works just fine for me, i.e. w/o having to explicitly set the aspect ratio. I'm using Anaconda-64bit distribution of Python 2.7.

import pylab as p  # or : import matplotlib.pyplot as p

Xmse = [2028.5457074044693,
 1653.3262637440594,
 1337.3889339729938,
 1176.2728864230257,
 1072.2873906521645,
 981.65920843213678,
 912.14636955892638,
 858.67713877925848,
 807.43207831735913,
 764.48689721143887]
boundary = [1,2,3,4,5,6,7,8,9,10] 

p.plot(boundary,Xmse)
p.show()
roadrunner66
  • 7,772
  • 4
  • 32
  • 38
  • When I do this I get an error: `There is no line property: "aspect"` – Alex Mar 11 '16 at 08:35
  • `plt.plot(boundary,Xmse, aspect='auto')` followed by `plt.show()` gives the error: `File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 184, in set_lineprops` `raise TypeError('There is no line property "%s"' % key)` `TypeError: There is no line property "aspect"` – Alex Mar 11 '16 at 08:38
  • Can you update your question and put all the code into one block? – roadrunner66 Mar 11 '16 at 09:28