Turn .plot() method in accessor so other pandas plotting methods are also available
See original GitHub issueCurrently GeoDataFrame.plot()
function overrides the pandas plot method, which means you cannot quickly plot your non-geometry columns.
The idea would be to follow the pattern from pandas where the plot() method is also an accessor like .plot.scatter() so those become available, while the default .plot()
would still override with the geometrical functionality.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top Results From Across the Web
pandas.DataFrame.plot — pandas 1.5.2 documentation
Allows plotting of one column versus another. Only used if data is a DataFrame. kindstr. The kind of plot to produce: 'line' :...
Read more >Plotting Visualizations Out of Pandas DataFrames
Plotting can be performed in pandas by using the “.plot()” function. This function directly creates the plot for the dataset.
Read more >Plotting with Pandas (…and Matplotlib…and Bokeh)
We first create the plot object using the plot() method of the data DataFrame. Without any parameters given, this makes the plot of...
Read more >Mapping and Plotting Tools - GeoPandas
Mapping shapes is as easy as using the plot() method on a GeoSeries or ... Plotting methods also allow for different plot styles...
Read more >How to make an accessor class like in pandas? - Stack Overflow
Here's a very basic implementation: >>> class FancyPlotting: ... def __init__(self, info: dict): ... self.info = info ... def plot(self, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the stream of consciousness here. I’m kind of working things out as I type. I looked a little closer at how Pandas accomplishes this. It has a class called
FramePlotMethod
that can be called either as a method or used as an accessor where the other plotting methods can be called (e.g.df.plot.line()
. The class is added as a property toDataFrame
through the use of another Pandas class calledCachedAccessor
.It appears GeoPandas does things a little bit differently. GeoPandas has a set of plotting methods defined in
plotting.py
as well as aplot()
method on theGeoDataFrame
class.It seems to me the best long term approach is to make a plotting class in GeoPandas similar to
FramePlotMethod
(e.g.GeoPlotMethod
). Then add it as a property by wrapping it in some sort of accessor. Maybe we can take advantage of Pandas’sCachedAccessor
here?However, I am not sure of the impact of moving those plotting methods in
plotting.py
into a class. That seems like it would be a breaking change in the API. We should be sensitive to that.An alternative is we create the class, but not migrate those functions into the new class. The class could proxy those functions, then over time migrate them to the class during a major version change.
TL;DR Version
GeoPlotMethods
.GeoPlotMethods
should proxy calls to original methods inplotting.py
.GeoPlotMethods
toGeoDataFrame
as a property using an accessor class such asCachedAccessor
.GeoPlotMethods
callable and migrate theGeoDataFrame.plot()
method from theGeoDataFrame
class toGeoPlotMethods
.DataFrame.plot
. This could possibly be done by having our newGeoPlotMethods
class extendFramePlotMethod
. This would allow for calls likegdf.plot.line()
,gdf.plot()
as well as future plotting techniques.Thoughts? Criticisms?
Closed by #1465