Skip to content
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 Moran scatterplot ported from splot #356

Merged
merged 7 commits into from
Jan 5, 2025

Conversation

martinfleis
Copy link
Member

@martinfleis martinfleis commented Jan 2, 2025

This adds a method to plot a scatterplot from Moran_Local and Moran based on the splot implementation with some changes.

  1. It is more restricted - always use standardised values, always enforce equal aspect
  2. Limited figure customisation - splot has opinionated style of axes. Leaving this to a user here.
  3. Rely on scipy to do the regression to avoid additional dependency on spreg.

As a follow up, I want to figure out a smart way of colour customisation but didn't give it much thought yet.

Regarding the API, should we go with plot_scatterplot or just simply scatterplot?

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.6%. Comparing base (e095b21) to head (51db7ab).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #356     +/-   ##
=======================================
+ Coverage   81.3%   81.6%   +0.2%     
=======================================
  Files         24      24             
  Lines       3335    3372     +37     
=======================================
+ Hits        2713    2750     +37     
  Misses       622     622             
Files with missing lines Coverage Δ
esda/moran.py 82.7% <100.0%> (+1.4%) ⬆️

@knaaptime
Copy link
Member

i like the idea that functions map to verbs whenever possible so i'd vote for maybe plot_scatter even though its the most different? i dunno

@knaaptime
Copy link
Member

knaaptime commented Jan 2, 2025

As a follow up, I want to figure out a smart way of colour customisation but didn't give it much thought yet.

if you ignore insignificant (or put it in the middle), then it should always be in order for a diverging colormap, then you can set nonsig separately? Like currently if you give Local_Moran.explore(cmap='coolwarm_r') it'll do the right thing, IIRC

@martinfleis
Copy link
Member Author

Like currently if you give Local_Moran.explore(cmap='coolwarm_r') it'll do the right thing, IIRC

Only if you have all 5 clusters present. If you, for example, don't have Low-High in your result, the mapping will become inconsistent.

@martinfleis martinfleis changed the title ENH: add Moran_Local.plot_scatterplot ported from splot ENH: add Moran scatterplot ported from splot Jan 3, 2025
Copy link
Member

@jGaboardi jGaboardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor punctuation adjustments in the docstrings.

esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
esda/moran.py Outdated Show resolved Hide resolved
@knaaptime
Copy link
Member

That's true but if you're sending your own cmap then youre taking that risk onto yourself imo. Choosing your own style means you might be choosing something misleading

@martinfleis
Copy link
Member Author

@jGaboardi where does the need to add full stops at the end of arg descriptions come from? Is that some style I am not aware of? Those are mostly not sentences that would require it from grammar perspective no?

@jGaboardi
Copy link
Member

It is simply my preference, as I think it's cleaner and more 'kept' looking. I'd not be offended if you did not accept the changes.

@martinfleis
Copy link
Member Author

Regarding the API, should we go with plot_scatterplot or just simply scatterplot?

i like the idea that functions map to verbs whenever possible so i'd vote for maybe plot_scatter even though its the most different? I dunno

@knaaptime I always thought that "scatter" in scatter plot is an adjective no? Is it also a noun?

@jGaboardi @sjsrey what is your take on the API?

splot currently uses moran_scatterplot

@knaaptime
Copy link
Member

i dunno english is ugly and this gets tricky. Technically 'scatterplot' is a noun.

...but I agree, i interpret the same way; "plot" is the verb, and scatter modifies the plot, so scatter is the adjective (which makes scatterplot an adverb?). I guess what I'm saying is 'pure' verbs are clearer than adverbs? Thus I prefer attempting to make things explicit: "plot the scatter", in which case scatter is a noun (the type of graph) and plotting is what we do to it

but really, its late and I'm not picky. I defer to your judgment :)

@sjsrey
Copy link
Member

sjsrey commented Jan 4, 2025

Regarding the API, should we go with plot_scatterplot or just simply scatterplot?

i like the idea that functions map to verbs whenever possible so i'd vote for maybe plot_scatter even though its the most different? I dunno

@knaaptime I always thought that "scatter" in scatter plot is an adjective no? Is it also a noun?

@jGaboardi @sjsrey what is your take on the API?

splot currently uses moran_scatterplot

+1 on plot_scatter

@jGaboardi
Copy link
Member

API and current naming (plot_scatter) look OK t me.

@martinfleis martinfleis merged commit e38e151 into pysal:main Jan 5, 2025
14 checks passed
@martinfleis martinfleis deleted the scatter branch January 5, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants