question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Turn .plot() method in accessor so other pandas plotting methods are also available

See original GitHub issue

Currently 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benabernathycommented, Oct 18, 2018

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 to DataFrame through the use of another Pandas class called CachedAccessor.

It appears GeoPandas does things a little bit differently. GeoPandas has a set of plotting methods defined in plotting.py as well as a plot() method on the GeoDataFrame 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’s CachedAccessor 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

  1. Create a new class called GeoPlotMethods.
  2. GeoPlotMethods should proxy calls to original methods in plotting.py.
  3. Add GeoPlotMethods to GeoDataFrame as a property using an accessor class such as CachedAccessor.
  4. Make GeoPlotMethods callable and migrate the GeoDataFrame.plot() method from the GeoDataFrame class to GeoPlotMethods.
  5. Find a way to proxy the call to a Pandas DataFrame.plot. This could possibly be done by having our new GeoPlotMethods class extend FramePlotMethod. This would allow for calls like gdf.plot.line(), gdf.plot() as well as future plotting techniques.

Thoughts? Criticisms?

0reactions
martinfleiscommented, Apr 14, 2021

Closed by #1465

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found