我有一个有两列的数据框。机器ID和价值。我将数据框按降序排序(首先是具有高值的机器),并绘制折线图。但是,它仍然显示x轴(MachineID 1到60,而不是首先获取最高值MachineID)
要解决此错误,请将machineID列更改为string,但仍然无法首先获取具有高值的计算机
示例数据帧:
MachineID Value
33 6.962754
16 6.955913
44 6.722355
31 6.320854
1 6.243701
9 5.894093
霉菌代码:
import plotly.express as px
fig = px.line(data, x="MachineID", y="Values")
fig.show()
上述代码的输出:
所需输出:
首先是具有高值的机器,依此类推
如果要使用线图并首先显示具有最高值的机器,则必须:
fig.update_xaxes(type='category')
示例代码:
结果图:
您可以在这里的分类轴上找到更多信息:
https://plotly.com/python/categorical-axes/
相关问题 更多 >
编程相关推荐