Skip to content

add moran_facette functionality and merge esda.moran plots to moran_scatterplot #27

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

Closed
wants to merge 2 commits into from

Conversation

slumnitz
Copy link
Member

@slumnitz slumnitz commented Jul 19, 2018

  • add moran_facet() with documentation, tests and examples
  • add moran_scatterplot() that can use all esda.moran objects as input
    with documentation, tests and examples

This pull requests builds ontop of bug fixes in #25
and depends on the integration of varnames in esda pysal/esda#23

@slumnitz slumnitz requested review from sjsrey, darribas and ljwolf July 19, 2018 22:16
__author__ = ("Stefanie Lumnitz <stefanie.lumitz@gmail.com>")


def value_by_alpha(x, alphay, gdf):
Copy link
Member

Choose a reason for hiding this comment

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

this should get dropped

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, I should have added value_by_alpha functionality is dealt with separately in the next pr #28

@@ -1062,3 +1160,113 @@ def moran_loc_bv_scatterplot(moran_loc_bv, p=None,
ax.plot(lag, fit.predy, **fitline_kwds)
ax.scatter(moran_loc_bv.zy, fit.predy, **scatter_kwds)
return fig, ax


def moran_facette(moran_matrix, figsize=(16,12),
Copy link
Member

Choose a reason for hiding this comment

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

I'd call it moran_facet, to align with other viz libraries (seaborn and ggplot2).

sharey=True, sharex=True)
fig.suptitle('Moran Facette')

for row in range(nrows):
Copy link
Member

Choose a reason for hiding this comment

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

Just as a suggestion: would it make sense to either use seaborn.FacetGrid to make our facets more abstract, that way making them more re-usable across the library? You might have considered this already and it might make not sense but just checking here. Ideally, if we're gonna have facets in several places of splot, the more we can reuse, the easier it'll be to maintain.

Copy link
Member Author

Choose a reason for hiding this comment

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

seaboard.FacetGrid takes as an input data : DataFrame Tidy (“long-form”) dataframe where each column is a variable and each row is an observation.

Since the Moran_BV_matrix returns Moran_BV objects I thought reusing the scatterplot, that plots Moran_BV objects is the way to go. Otherwise we would need a Moran_Matrix that returns spatially lagged values and values.


Returns
-------
fig : Matplotlib Figure instance
Copy link
Member

Choose a reason for hiding this comment

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

Does it always return a fig object? Even when ax is not None? I couldn't tell, but usually, if you pass and ax I think usually you return only ax (not completely sure though).

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it always returns a fig. If ax is not None, else: fig = ax.get_figure() will create a fig.




def value_by_alpha(x='attribute', y='alpha_attribute', c, data=geodataframe):
Copy link
Member

Choose a reason for hiding this comment

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

This method name is picked in L.13, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, I should have added value_by_alpha functionality is dealt with separately in the next pr #28

fig, ax = geodataframe.plot(x, color=rgba)
return fig, ax

def make_RGBA_array_from_attribute(x):
Copy link
Member

Choose a reason for hiding this comment

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

This is unfinished, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, I should have added value_by_alpha functionality is dealt with separately in the next pr #28


def value_by_alpha(x='attribute', y='alpha_attribute', c, data=geodataframe):
rgb = matplotlib.colors.to_rgba_array(c)
alpha_channel = x/y.max()
Copy link
Member

@ljwolf ljwolf Jul 20, 2018

Choose a reason for hiding this comment

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

This is great! could we generalize it a bit? I'd like to be able to have:

  1. diverging scaling (extremes are opaque, middle is transparent, something like (x-np.median(y)).abs() / np.abs(y).max()
  2. logarithmic scaling (including log divergent), which changes over the log of y (or y + y.min() rather than y directly, if y has negative elements)

Copy link
Member Author

Choose a reason for hiding this comment

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

I can try add more functionality to #28 :)

@slumnitz
Copy link
Member Author

slumnitz commented Aug 3, 2018

@ljwolf @darribas @sjsrey This currently still fails due to spot's dependencies in giddy and spreg and the change of the libpysal API.

@ljwolf ljwolf added the blocked this is blocked by a change needed somewhere else label Aug 7, 2018
@slumnitz slumnitz force-pushed the facette branch 2 times, most recently from d80065a to d7ec801 Compare August 21, 2018 20:34
@ljwolf
Copy link
Member

ljwolf commented Sep 11, 2018

Now, this is redundant, yes?

@slumnitz slumnitz removed the blocked this is blocked by a change needed somewhere else label Sep 14, 2018
@jGaboardi
Copy link
Member

Should the PR be closed or is it still in play?

@slumnitz
Copy link
Member Author

@jGaboardi Thank you this can be closed.

@slumnitz slumnitz closed this Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants