问题
I want to draw a choropleth world map with a slider for the year values. It would be a combination of the "Choropleth Map" and the "Adding Sliders to Animations" (https://plot.ly/python/).
First I searched plotly's community forum and the web for an example of a plotly choropleth map with grid data or a slider without success.
While I managed to replicate the slider animation example with my data (see jupyter notebook link below), adapting the choropleth code to access grid data with a slider does not seem to work.
In contrast to a regular map (like in example one), data is not loaded from a dataframe column but is uploaded to a plotly grid. In example two we can see that instead of regular x,y and text values in the data_dict, xsrc, ysrc and textsrc are used to access the grid data.
data_dict = {
'xsrc': grid.get_column_reference(col_name_template.format(
year=year, continent=continent, header='lifeExp'
)),
'ysrc': grid.get_column_reference(col_name_template.format(
year=year, continent=continent, header='gdpPercap'
)),
Chloropleth maps are defined in plotly by setting locations, z-values and text values in list form. In order to check if plotly choropleth maps support grid data, I searched in the api-documentation and found equivalents: locationsrc, zsrc, and textsrc. Therefore using grid data should be possible. When I draw my adapted graph though, I see only the coastline and the slider but no countries being highlighted.
A jupyter notebook with code and data with additional links can be found here: https://github.com/MathiasRiechert/plolty-choropleth-slider-notebook/blob/master/choropleth-slider-notebook.ipynb
Unfortunately, I can't find a way to debug why nothing is shown in the map. Is there a way to debug why nothing is shown on the plotly website? What else reasons might cause that nothing is shown?
来源:https://stackoverflow.com/questions/41858725/python-plotly-how-to-make-a-choropleth-map-with-a-slider-access-grid-data-issu