Support for Basemap
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 254
- Avg merge
- 10h 35m
- Merged PRs (30d)
- 9
Description
@nimisha-18, I was able to add a basemap by implementing a custom geom subtype that adds the basemap during plotnine.ggplot's draw phase:
from __future__ import annotations
import typing
import pandas as pd
from plotnine.geoms.geom import geom
import contextily as ctx
if typing.TYPE_CHECKING:
from typing import Any
import pandas as pd
from matplotlib.axes import Axes
from plotnine.coords.coord import coord
from plotnine.iapi import panel_view
class geom_basemap(geom):
DEFAULT_PARAMS = {
"stat": "identity",
"position": "identity",
"na_rm": False,
"crs": "EPSG:3857",
"source": ctx.providers.OpenStreetMap.Mapnik,
}
def draw_panel(
self,
data: pd.DataFrame,
panel_params: panel_view,
coord: coord,
ax: Axes,
**params: Any,
):
crs = params["crs"]
source = params["source"]
ctx.add_basemap(ax, crs=crs, source=source)
To use it in your example, you would just add it like any other layer:
plot3 = plot2 + geom_basemap(source=ctx.providers.OpenStreetMap.Mapnik)
plot3.show()
Aside, the geom_basemap concept as a geom, at least to me, doesn't fit well with the ideas outlines in The Grammar of Graphics. Im not sure what category a basemap falls within so calling this a geom is likely conceptually incorrect. Just something to think about.
Originally posted by @aaraney in https://github.com/has2k1/plotnine/discussions/850#discussioncomment-12436571
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposed custom geom_basemap implementation and how plotnine.ggplot handles its draw phase. Compare the contextily basemap example with the Grammar of Graphics concepts, then determine the appropriate API and category for basemap support. Done means an agreed design with implementation and coverage for the supported usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100