如何设置y轴范围,而不是python上列表的每个值?

问题描述 投票:0回答:1

我正在努力如何在Y轴上设置范围数字以摆脱所有值,而且我也在尝试删除该行并仅设置'+'标记,我已经尝试了所有方法:ylim,轴...在此先感谢

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()
python-2.7 matplotlib
1个回答
1
投票

[尝试将y值显式转换为数字(浮点数或整数)。在您的代码中,您可以尝试例如:

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()
© www.soinside.com 2019 - 2024. All rights reserved.