我想将数据框的 x 和 y 绘制为整数和百分比。Y 轴搞砸了。如何修复它以重新排序 y 轴?[复制]

I want to draw a plot of x and y of a data frame as integers and percentages. the y axis messing up. how do I fix it to re-order the y axis? [duplicate]

提问人:Kaaj 提问时间:10/31/2023 最后编辑:WoodfordKaaj 更新时间:10/31/2023 访问量:26

问:

plt.figure (figsize=(20,30), dpi=80)
plt.scatter (df3['Crude oil average price $ per barrel'],df3['Competition rate'])
plt.xlabel ("Crude oil average price $ per barrel")
plt.ylabel('Competition rate percentage')

绘图在 y 轴上搞砸了,无法排序,因为 cvs 文件不包含浮点数或整数:

plot has messed up in y axis and could not be sorted because cvs file doesn't contain float or integers

python matplotlib yaxis

评论

1赞 BigBen 10/31/2023
将数据转换为浮点数,然后使用 PercentFormatter
0赞 Trenton McKinney 10/31/2023
df3['Competition rate'是字符串。
0赞 Trenton McKinney 10/31/2023
df3['Competition rate'] = df3['Competition rate'].str.replace('%', '').astype(float)
1赞 Kaaj 10/31/2023
谢谢。问题已经解决。

答: 暂无答案