【问题标题】:How to set the number of decimal places in a Ploty Animation slider - Python如何在 Plotly Animation 滑块中设置小数位数 - Python
【发布时间】:2021-05-17 11:49:34
【问题描述】:

我正在将 Dataframe 绘制到 Plotly Express 动画中。 Slider 使用'shot' 数字,所有数字都是整数(没有小数位)。当 Slider 显示时,它有小数位,如何删除它们? 来自数据框的样本。

shot    Easting Northing    Depth
1001    455951.7    7328194.4   2.5
1002    455301.6    7326908.9   2.5
1003    455327.8    7326897.2   2.5
1004    455880.7    7328069.7   2.5
1005    455875.3    7328058.5   2.5
1006    455869.8    7328047.2   2.5
1007    455864.3    7328036.0   2.5
1008    455858.8    7328024.8   2.5
1009    455853.3    7328013.6   2.5
1010    455847.8    7328002.3   2.6
1011    455842.3    7327991.1   2.6
1012    455836.8    7327979.9   2.6
1013    455831.3    7327968.7   2.6
1014    455825.8    7327957.4   2.6
1015    455820.3    7327946.2   2.6
1016    455814.8    7327935.0   2.6
1017    455809.3    7327923.8   2.6
1018    455803.8    7327912.6   2.6
1019    455798.3    7327901.4   2.6

代码。我已经将数据称为 dfAnime

        ## Animated plot
        import plotly.express as px
        fig = px.scatter(dfAnime, x="Easting", y="Northing", animation_frame="shot",
            color='Depth',range_x=[np.min(dfAnime['Easting']),np.max(dfAnime['Easting'])],
            range_y=[np.min(dfAnime['Northing']),np.max(dfAnime['Northing'])])
            
        fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"]=100 # Sets speed. Comment out to turn off play/stop button
        fig.update_yaxes(
            scaleanchor="x",
            scaleratio=1,
            exponentformat='none')
        fig.update_xaxes(
            scaleanchor="x",
            scaleratio=1,
            exponentformat='none')
        fig.update_layout(template="plotly_dark")           
        #fig.show()

【问题讨论】:

    标签: python animation slider plotly


    【解决方案1】:

    答案是数据类型,它应该是 Int 而不是 float(来自父数据帧的结转)。
    以下内容来自 Plotly 社区论坛上发布的同一问题。

    如果 shot 列是 同一数据帧中的整数。

    你能用dfAnime.dtypes检查列的数据类型吗?

    如果不是int64,那么您可以使用此将列更改为int64 命令dfAnime.shot = dfAnime.shot.astype(int)

    我认为数据类型不是int64,可能是objectfloat64 这可能会导致此错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      相关资源
      最近更新 更多