Python plotly scatter_geo modify hover data(Python plotly scatter_geo 修改悬停数据)
本文介绍了Python plotly scatter_geo 修改悬停数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想修改悬停数据并将其留给例如只有 bins 数据.我做了以下代码,但 hover_data 参数不起作用.修改har数据的方法是什么?
I want to modify hover data and leave ther for e.g. only bins data.
I made following code, but hover_data parameter didn't work. What is the way to modify haver data?
import plotly.express as px
import plotly.graph_objs as go
import pandas as pd
rows=[['501-600','15','122.58333','45.36667'],
['till 500','4','12.5','27.5'],
['more 1001','41','-115.53333','38.08'],
]
colmns=['bins','data','longitude','latitude']
df=pd.DataFrame(data=rows, columns=colmns)
df = df.astype({"data": int})
fig=px.scatter_geo(df,lon='longitude', lat='latitude',
color='bins',
opacity=0.5,
size='data',
projection="natural earth", hover_data=(['bins']))
fig.add_trace(go.Scattergeo(lon=df["longitude"],
lat=df["latitude"],
text=df["data"],
textposition="middle center",
mode='text',
showlegend=False))
fig.show()
推荐答案
scatter_geo 的 hover_data 参数可以参考如下.
you can mention as below for hover_data argument of scatter_geo.
import plotly.express as px
import plotly.graph_objs as go
import pandas as pd
rows=[['501-600','15','122.58333','45.36667'],
['till 500','4','12.5','27.5'],
['more 1001','41','-115.53333','38.08'],
]
colmns=['bins','data','longitude','latitude']
df=pd.DataFrame(data=rows, columns=colmns)
df = df.astype({"data": int})
fig=px.scatter_geo(df,lon='longitude', lat='latitude',
color='bins',
opacity=0.5,
size='data',
projection="natural earth", hover_data={'longitude':False,'latitude':False,'data':False})
fig.add_trace(go.Scattergeo(lon=df["longitude"],
lat=df["latitude"],
text=df["data"],
textposition="middle center",
mode='text',
showlegend=False))
fig.show()
在 hover_data 中将列名设置为 False 将从 hover_data 中删除该列名.希望这能回答您的问题.
Setting the columns name as False in hover_data will remove that column name from hover_data. Hope this answers your question.
这篇关于Python plotly scatter_geo 修改悬停数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Python plotly scatter_geo 修改悬停数据
基础教程推荐
猜你喜欢
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
