这可能是一个完全愚蠢的问题,但是我无法在python中访问plotly对象的某些字段。到目前为止,我刚与Java进行过很多合作,而我的新大学希望我编写一些python的东西,而这些东西可能卡在了我的Java思维方式中。
问题:
如何访问绘图/氯体积图的内部字段?
代码示例:
首先,我导入情节表达并创建一个情节世界地图,以后我要用它来选择一个国家
import plotly.express as px
gapminder = px.data.gapminder().query("year == 2007")
mapfig = px.scatter_geo(gapminder,locations="iso_alpha",hover_name="country",size="pop")
后来我通过html形象化了数字
html.Div(
dcc.Graph(
id='country-selector',figure=mapfig,)
)
当我现在运行python脚本时,我会看到一个世界地图,并且可以将鼠标悬停在任何国家/地区,看到带有人口和县名的弹出窗口。到目前为止,一切都很好。现在要解决的问题:当我尝试更新其他图形时,我稍后无法在代码中访问国家/地区或hover_name。
我想象的样子:
html.Div(
dcc.Graph(
id='country-selector',hover_name= --> here i need some kind of java style getter on the hover_name of mapfig
)
)
@app.callback(
dash.dependencies.Output('graph-indicator-1','figure'),[dash.dependencies.Input('country-selector','hover_name')])
def update_other_graph(hover_name,selected_value_for_indicator_1):
--> here i want to work with hover_name (the name of the hovered country of my world map)
也许有人比我更精通python,并且知道答案。谢谢您的时间!