M. Mariscal
M. Mariscal

Reputation: 1328

How to set y axis range instead of every value of the list on python?

I'm struggling about how can i set a range numbers on Y axis to get rid of every value, also i'm trying to remove the line and just set the '+' marks, i've tried everything: ylim, axis... Thanks in advance

wtf

CODE:

plt.yticks(np.arange(0, 100)+1)  # i'm trying to fix my problem with this
plt.xlabel('x')
plt.ylabel('x')
plt.xticks(rotation=90)
#plt.plot(blabla['data0'], marker='+', color='mediumaquamarine', label=2018)
#plt.plot(blabla['data11'], marker='+', color='r', label=2017)
plt.plot(blabla["gdsgweg"], blabla["wefwef"], marker='+', color='red', label=2017)
plt.plot(blabla["wefwfe"], blabla["wefwf"], marker='+', color='mediumaquamarine', label=2018)
from matplotlib.ticker import MaxNLocator
plt.gca().xaxis.set_major_locator(MaxNLocator(prune='lower'))  # i'm trying to fix my problem with this
plt.legend()
plt.show()

Upvotes: 0

Views: 177

Answers (1)

Eric M
Eric M

Reputation: 1418

Try explicitly converting your y-values to numbers (either float or int). In your code you could try for example:

blabla["wefwef"] = pd.to_numeric(blabla["wefwef"], errors='coerce')
blabla["wefwf"] = pd.to_numeric(blabla["wefwf"], errors='coerce')

plt.yticks(np.arange(0, 100)+1)  # i'm trying to fix my problem with this
plt.xlabel('x')
plt.ylabel('x')
plt.xticks(rotation=90)
plt.plot(blabla["gdsgweg"], blabla["wefwef"], marker='+', color='red', label=2017)
plt.plot(blabla["wefwfe"], blabla["wefwf"], marker='+', color='mediumaquamarine', label=2018)
from matplotlib.ticker import MaxNLocator
plt.gca().xaxis.set_major_locator(MaxNLocator(prune='lower'))  # i'm trying to fix my problem with this
plt.legend()
plt.show()

Upvotes: 1

Related Questions