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

Python 2.7 如何在python上设置y轴范围而不是列表的每个值?,python-2.7,matplotlib,Python 2.7,Matplotlib,我在苦苦思索如何在Y轴上设置一个范围数字来去除所有值,同时我也在尝试删除这条线,只设置“+”标记,我已经尝试了所有方法:ylim,axis。。。提前谢谢 代码: 尝试显式地将y值转换为数字(float或int)。在代码中,您可以尝试以下操作,例如: blabla["wefwef"] = pd.to_numeric(blabla["wefwef"], errors='coerce') blabla["wefwf"] = pd.to_numeric(blabla["wefwf"], errors=

我在苦苦思索如何在Y轴上设置一个范围数字来去除所有值,同时我也在尝试删除这条线,只设置“+”标记,我已经尝试了所有方法:ylim,axis。。。提前谢谢

代码:


尝试显式地将y值转换为数字(float或int)。在代码中,您可以尝试以下操作,例如:

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()

你能粘贴你的代码吗?你忘了将数据转换成数字。它们已经是数字了,如果不是,就不能在绘图上表示出来……我如何从y轴删除所有数据并将其设置为0到1000?因为ylim没有工作,所以我知道这可能是问题所在,因为我得到:ValueError:无法将字符串转换为float:NA,但在我执行blabla['Price']=Blablabla['Price']之前。fillna(0)无法理解错误原因…请尝试
pd.to_numeric()
方法,使用
errors='concurve'
参数强制字符串为
nan
valuesok我的朋友,我修复了它,你是对的,我使用的是“FILLNA”方法,但问题是数据是字符串NA,并且在使用该方法后它没有改变,因为现在我会小心处理我处理的数据,没有想到它,我对str进行了替换转换,然后使用“ASTYPE(FLOAT)”方法在绘图上进行替换
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()