Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing period_label to plot_animated on a GeoDataFrame has no effect if basemap set. #39

Open
hraftery opened this issue Oct 10, 2021 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@hraftery
Copy link

Describe the bug
Plotting a GeoDataFrame using plot_animated takes an optional period_label parameter that can be used to style the date/time label that appears on the graph in each frame. Except, it turns out, if a contextily basemap is specified, as is done with the basemap_format argument. If so, the period_label parameter is ignored and it is not possible to style or position the period label text.

To Reproduce
This is as per the documention, with the addition of the period_label argument.

import geopandas
import pandas_alive
import contextily

gdf = geopandas.read_file('data/italy-covid-region.gpkg')
gdf.index = gdf.region
gdf = gdf.drop('region',axis=1)

map_chart = gdf.plot_animated(filename='examples/example-geo-polygon-chart.gif',basemap_format={'source':contextily.providers.Stamen.Terrain}, period_label={'foo':'bar'})

Expected behavior
The period_label key-value pairs to be interpreted as they are in the non-geopandas examples in the documentation.

Additional context
The following diff on pandas_alive/geocharts.py fixes the issue. Turns out the problem is that the first frame is determined by the number of strings already added to the axes text (where the period label is set), but adding a basemap sets the axes text to the attribution string for that basemap, so there is always already one string already set. I have elected to leave the attribution text be, so the period label can be positioned elsewhere and styled differently so the attribution still appears as desired. A separate flag could be added to remove the attribution is desired.

253,262c260,265
<             num_texts = len(self.ax.texts)
<             if num_texts == 0:
<                 # first frame
<                 self.ax.text(
<                     s=s,
<                     transform=self.ax.transAxes,
<                     **self.get_period_label(self.period_label),
<                 )
<             else:
<                 self.ax.texts[0].set_text(s)
---
> 
>             self.ax.text(
>                 s=s,
>                 transform=self.ax.transAxes,
>                 **self.get_period_label(self.period_label),
>             )
hraftery added a commit to hraftery/pandas_alive that referenced this issue Oct 20, 2021
@JackMcKew JackMcKew added the help wanted Extra attention is needed label Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants