-
Notifications
You must be signed in to change notification settings - Fork 26
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
Visualising Local Autocorrelation #8
Conversation
accept both moran and moran_local as inputs and adapt test for both versions
added example in notebook updated connected functionality
bug fix in three-plot-visualization
started use of geoJSONDataSource for Bokeh plots
also initialize input as GeoJSONDataSource rewrite utility functions
move mask behind datapoint
clean .py files with pyflakes
…sation and add tests
finalize notebooks for MPL and Bokeh three-plot implementation add notebooks testing on Columbus dataset
add files working towards `splot.namespace` API
@sjsrey @darribas @ljwolf @TaylorOshan @jorisvandenbossche Hi everyone, here the first official splot GSoC pull request! Still To-Do:
|
masking option of region is now visible together with quadrant masking fixed coloration bug in bokeh.plot_local_autocorrelation changed scaling of single visualizations in bokeh.plot_local_autocorrelation
Also fix two imports in test files
…ough install directly from github instead with pip.
it was not so easy to make TravisCI run all the tests, but it's finally green:) |
change mplot to use ColumnDataSource for three plot make everything come from the same geoJSONDataSource therefore split functionality in two parts, data source creation and figure creation
therefore, change add_legend() in _viz_utils.py
add outline around selected polygons in tap tool for clarity
…different figure ratios implement calc_data_aspect() in map visualizations and add x and y_ranges place legend below maps for nicer visualization change sizing_mode of three-plot to `scale-width` and changed title of three-plot visualization to "Local Spatial Autocorrelation"
- pip install libpysal | ||
# Pysal still needed for code not yet moved to libpysal | ||
- pip install pysal | ||
- pip install esda | ||
- pip install mapclassify | ||
- pip install -r requirements_dev.txt | ||
- pip install . | ||
# Now install splot (don't use 'pip install .', we'll run out of space) |
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.
weird... that happens on travis?
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 was in /tmp/...
; it seems pip
copies everything in the folder, which includes the miniconda
environment.
splot/_viz_bokeh.py
Outdated
>>> show(fig) | ||
''' | ||
# We're adding columns, do that on a copy rather than on the users' input | ||
df = df.copy() |
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.
I thought from our last conversation, we agreed that df.assign(...)
would make a copy already? In a few cases, you're making more than one new column, so keep this copying as is I guess.
But, if I recall correctly, @jorisvandenbossche was suggesting like... for the column name-style argument in geodataframe.plot('colname', **options)
, you could pass geodataframe.plot(numpy_vector, **options)
to plot without assign
, or copy
?
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.
Ok, yep for the _viz_mpl.py
file I am using the df.assign() already. My thoughts were, too, that df.assign might not work if I have to add multiple columns which is the case for the three-plot visualisations.
However, I am not using the .plot() functionality in _viz_bokeh.py
at all and was wondering if you guys would have any suggestions how to handle adding columns here, besides using "df.copy()". I am happy to also just leave this as it is for now and add a note for future improvements.
Yeah, you could assign and then drop after you're done plotting?
On Wed, May 30, 2018, 18:31 Stefanie Lumnitz ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In splot/_viz_bokeh.py
<#8 (comment)>:
> + >>> import esda
+ >>> from splot.bk import plot_choropleth
+ >>> from bokeh.io import show
+
+ >>> link = examples.get_path('columbus.shp')
+ >>> df = gpd.read_file(link)
+ >>> w = lp.Queen.from_dataframe(df)
+ >>> w.transform = 'r'
+
+ >>> TOOLS = "tap,help"
+ >>> fig = plot_choropleth(df, 'HOVAL', title='columbus',
+ ... reverse_colors=True, tools=TOOLS)
+ >>> show(fig)
+ '''
+ # We're adding columns, do that on a copy rather than on the users' input
+ df = df.copy()
Ok, yep for the _viz_mpl.py file I am using the df.assign() already. My
thoughts were, too, that df.assign might not work if I have to add multiple
columns which is the case for the three-plot visualisations.
However, I am not using the .plot() functionality in _viz_bokeh.py at all
and was wondering if you guys would have any suggestions how to handle
adding columns here, besides using "df.copy()". I am happy to also just
leave this as it is for now and add a note for future improvements.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACJY833amrOnDJ0PxwZoRYmHtReZFqxdks5t3teHgaJpZM4UOdDS>
.
--
Levi John Wolf
Lecturer in Quantitative Human Geography | University of Bristol
Fellow | Center for Spatial Data Science, University of Chicago
Associate Member | Center for Multilevel Modeling, University of Bristol
Interim Director | Q-Step Program, University of Bristol
ljwolf.org
|
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.
Didn't look at everything in detail, but added a couple of comments
splot/_viz_mpl.py
Outdated
k=2, cmap=hmap, linewidth=0.1, ax=ax, | ||
edgecolor='white', legend=legend, legend_kwds=legend_kwds) | ||
ax.set_axis_off() | ||
return fig |
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.
I personally think it can be more useful to return the ax
, because often you need the ax to further modify the figure (although of course some things like saving the figure rather needs the fig
object ..)
This is also what geopandas does (and I think eg also seaborn)
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.
I changed the returns for lisa_cluster()
to fig, ax
. I think this should be part of the discussion about the splot API, so I added this here: #9
splot/_viz_mpl.py
Outdated
---------- | ||
moran_loc : esda.moran.Moran_Local instance | ||
Values of Moran's Local Autocorrelation Statistic | ||
df : geopandas dataframe instance, optional |
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.
currently it is not "optional" because it is a positional argument in the function signature, so you actually need to pass one
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.
ok, this was changed df is not an "optional' input
splot/_viz_mpl.py
Outdated
angle=mask_angles[quadrant], | ||
color='grey', zorder=-1, alpha=0.8)) | ||
# quadrant selection in maps | ||
non_quadrant = ~(moran_loc.q==quadrant) |
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.
pep8: spaced around ==
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.
all pep8 issues are fixed
splot/_viz_mpl.py
Outdated
# quadrant selection in maps | ||
non_quadrant = ~(moran_loc.q==quadrant) | ||
mask_quadrant = df[non_quadrant] | ||
df_quadrant = df.iloc[moran_loc.q == quadrant] |
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.
you can reuse the mask you created above?
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.
Yes, thanks that works!
|
||
|
||
__all__ = ['mplot'] | ||
|
||
|
||
def mplot(m, xlabel='', ylabel='', title='', custom=(7,7)): | ||
def mplot(m, xlabel='', ylabel='', title='', figsize=(7,7), p=None, ax=None, |
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.
I don't know to what extent you are bound to historical names, but for clarity and for consistency with the other functions, I would personally rather call this something like plot_moran
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.
Also, should this be moved to splot.mpl
? (or at least also exposed there, so people can import it from there)
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.
Good point, I also added this to the API discussion: #9
changed parameter description for `.mpl` `lisa_cluster`, df is not an optional input deleted `df['labels'] = labels in `_viz_utils.py` to not change the input df added `df.assign()` wherever one column needed to be added and df.copy() where multiple columns were added added `ax` as return for `.mpl` `lisa_cluster`
…or clarity and change colors
changed coloring for `mplot`
and change `mplot` name to `moran_scatterplot` in mpl and bokeh version add tests for `.mpl` `moran_scatterplot` change default colors for bokeh and mpl plots
Please enter the commit message for your changes. Lines starting
creating a three plot visualisation for spatial autocorrelation
mplot.py
for implementation in three-plot visualisationsimport splot.namespace