-
Notifications
You must be signed in to change notification settings - Fork 79
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
ENH: add vectorized plotting to Graph #593
Conversation
We have also discussed today to allow partial plots, like for a single focal or a subset of those. @sjsrey how would you like the API around that be shaped? Additional keyword |
Codecov Report
@@ Coverage Diff @@
## main #593 +/- ##
=======================================
+ Coverage 83.9% 84.4% +0.5%
=======================================
Files 127 139 +12
Lines 14804 14945 +141
=======================================
+ Hits 12420 12607 +187
+ Misses 2384 2338 -46
|
This should be ready now. Allowing for filtering by focal or an array of them. |
A further note - this depends on index of the gdf to match graph nodes to geometries. I suppose that once we'll have a proper look ad the ID handling in the Graph, this may change. But so far it is consistent with everything else. |
Two use cases come to mind. Let's say The second use case would be to "zoom in" on the induced subgraph, so the extent may/will change depending on the focal units specified. For each of these cases, there is the issue of distinguishing the edges incident with each of the focal units. In cases where the members of focal are pairwise disjoint, a different color for the edges incident with each focal node would do the job. When a pair of focal nodes are neighbors, I'm not sure what the best way to handle that would be? This is all assuming a static plot, in which everything has to be shown at once. With interactivity, looping over the focal units would allow the subgraph incident with each focal unit to be uniquely portrayed. But that is down the road. Just some thoughts here. The PR looks great to me in terms of implementation and test coverage! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done without distinguish the focal pairwise edges as import geopandas as gpd
import geodatasets
from libpysal import graph
df = gpd.read_file(geodatasets.get_path("geoda.nyc_neighborhoods"))
contiguity = graph.Graph.build_contiguity(df)
ax = contiguity.plot(df)
contiguity.plot(df, focal=[7, 94], color="red", ax=ax)
For this we would need to set axis limits based on the extent of subgraph. With the upcoming commit: ax = G.plot(df)
G.plot(df, focal=[7, 94], color="red", ax=ax, limit_extent=True)
This sounds like a lot of complication of the code and the API. Can we leave it for a potential follow-up if there will be an appetite to look into that? |
this looks sweet. One quick thing looking at the plots since i wasnt around for the sprint is, it would be nice if you could distinguish the focal(s) from the neighbors in the subgraph(s). Different color or something |
I'd like to avoid to have way too many
neither was this topic :D |
indeed. in these contiguity examples its pretty easy to intuit, but in more complicated graphs it's useful to have a way to distinguish |
New implementation of plotting. A fast one :).
Using
geodatasets.get_path("geoda south")
, the oldW.plot()
takes1.76 s ± 86 ms per loop
to plot. The newGraph.plot()
takes15 ms ± 146 µs per loop
, both resulting the equal plot.The API is nearly identical to
W.plot()
with some minor tweaks like the ability to control whether the nodes shall be plotted or figsize keyword when creating a new ax.Tests will come.