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 Free
Top 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

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
FramePlotMethodthat 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 toDataFramethrough 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.pyas well as aplot()method on theGeoDataFrameclass.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’sCachedAccessorhere?However, I am not sure of the impact of moving those plotting methods in
plotting.pyinto 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.GeoPlotMethodsshould proxy calls to original methods inplotting.py.GeoPlotMethodstoGeoDataFrameas a property using an accessor class such asCachedAccessor.GeoPlotMethodscallable and migrate theGeoDataFrame.plot()method from theGeoDataFrameclass toGeoPlotMethods.DataFrame.plot. This could possibly be done by having our newGeoPlotMethodsclass extendFramePlotMethod. This would allow for calls likegdf.plot.line(),gdf.plot()as well as future plotting techniques.Thoughts? Criticisms?
Closed by #1465