0

I have my x-axis which needs to go from 1 to 10 and my y-axis needs to go from 1 to 10.

From there I want to plot in two lists and compare them in that range.

I can't get my y-axis to work. I've been trying to follow the matplot's documentation samples.

import matplotlib.pyplot as plt


list1 = ['3', '3', '4', '5', '7']
list2 = ['5', '4', '5', '6', '5']

plt.plot(10,10,list1,'g--')
plt.plot(10,10,list2,'r-o')
plt.show()

My output

Note on proposed duplicate

I don't believe the duplicate post is similar to my post. The post you refer to is describing how categorical plots have been introduced so I learned that a newer version of matplot is somehow the reason, but shouldn't it still be possible to do in this newer version? And that post you refer to is not showing any kind of solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
jubibanna
  • 1,095
  • 9
  • 21
  • I'm sorry you did not understand the solution of the duplicate. I will repeat it here for your case: `list1 = [float(i) for i in list1]`. Same for list2. – ImportanceOfBeingErnest Dec 17 '18 at 17:47
  • It worked, thanks! And thanks for the sarcasm <3 Merry christmas :) – jubibanna Dec 17 '18 at 18:09
  • There is no sarcasm involved from my side. I would have though the duplicate answer is clear enough, but if you have a suggestion on how to word it better or any other improvements that would have prevented you from not understanding it, I'm happy to hear about them. – ImportanceOfBeingErnest Dec 17 '18 at 18:49

3 Answers3

1

You can try plt.ylim and plt.xlim.

Documentation at: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.ylim.html

ycx
  • 3,155
  • 3
  • 14
  • 26
0

You can use xticks and yticks here is an example

pars3c
  • 13
  • 4
  • list1 = ['3', '3', '4', '5', '7'] plt.xticks(0,10) plt.yticks(0,10) plt.plot(list1) will give you a weird result, where the y-axis is changed to correspond list1. – jubibanna Dec 17 '18 at 17:42
0

plt.axis should also work as well.

fstop_22
  • 971
  • 5
  • 9
  • list1 = ['3', '3', '4', '5', '7'] plt.axis([0, 10, 0, 10]) plt.plot(list1) will give you a weird result, where the y-axis is changed to correspond list1. – jubibanna Dec 17 '18 at 17:41