pysal / splot

Lightweight plotting for geospatial analysis in PySAL
BSD 3-Clause "New" or "Revised" License
98 stars 26 forks source link

sugguestion about plot_local_autocorrelation #60

Open stevenlis opened 5 years ago

stevenlis commented 5 years ago

pysal: 2.0.0

It's my first time to plot with splot and I think maybe I can offer some suggestions as I've seen many idea collection issues.

download

  1. plot_local_autocorrelation doesn't seem supporting ax, so it might be a good idea to add a arg to control the layout e.g., 3 by 1 or 1 by 3. (the function does return one Fig and three Axes. Is there any way to manipulate them just as any Axes? Maybe I missed something.)

  2. adding a map_kwds or something to control the maps.

  3. Since the slope of the line in the Moran scatterplot represents the global Moran's I, it might be a good idea to set xlim equal to ylim, so that a line flatter than 45 degrees means the Moran's I is less than 0.5. Since different xlim and ylim will visually affect the slope of the line, it may cause problem sometimes especially when we compare two plots. (Btw, Geoda doesn't plot outliers in the Moran scatterplot, so I'm curious of how outliers are handled in splot)

  4. display global Moran's I and its p-value. I think most of the time, we need it as well.

  5. The current API seems to use Local Moran object as input. Every time I change the variable I want to plot, then I have to calculate it again, so I think it might be easier to actually just use the columns as input.

  6. I'm actually curious if it is possible to simplify the API of splot to just have one function and then use args to choose which plot to display like lisa_cluster=False.

Btw, thanks for this amazing work and user-friendly package that makes plotting easy with Python.๐Ÿ’•๐Ÿ’•๐Ÿ’•

slumnitz commented 5 years ago

Hello @StevenLi-DS,

thank you for your suggestions and ideas! We are always grateful for feedback and happy to accommodate users as much as possible! In fact, we are currently working to implement 3. in #51 . Your point 1. and 4. will most likely be part of the next release as well, these are great additions!

As to your first point, I am not sure if I understood you correctly, you can manipulate single Axes through defining fig, axs = plot_local_autocorrelation() and e.g. calling axs[0].set_axis_off(). I think adding a layout option is a great idea though, since Matplotlib currently does not support rearranging axes once a figure is drawn. Alternatively, you could directly use the moran_scatterplot(ax=axs[0,0]) lisa_cluster(ax=axs[0,1]) andgdp.plot(ax=axs[0,2]) and arrange them in a new figure in a format you would like.

What exactly would you like to have more control over in 2. with a map_kwds?

Thanks again for the suggestions! We are happy to hear splot is making your life easier!

stevenlis commented 5 years ago

Hi, @slumnitz. Thanks for your reply.

I actually tried fig, axs = plot_local_autocorrelation() before posting and it seems like I missed something and I just tried it again and indeed it's working as expected.

What exactly would you like to have more control over in 2. with a map_kwds?

The doc says the map plots use .plot() in geopandas so I wish I could pass some kwds to control the map. For example, for the above plot, I may wanna set the edge color to grey or something. I actually eventually end up using moran_scatterplot() and lisa_cluster() as receiving they would give me more controls.๐Ÿ˜Š

qizidog commented 2 years ago

Some more feedback, I'm trying to explore autocorrelation of some linestring geometry through plot_local_autocorrelation() and lisa_cluster() method, but a figure without anything except a legend is returned. Everything works as expected after changing the linestring geometry to it's centroid point geometry. I guess that the linestring geometry is not supported perfectly enough?

The version of splot is 1.1.4

qizidog commented 2 years ago

Some more feedback, I'm trying to explore autocorrelation of some linestring geometry through plot_local_autocorrelation() and lisa_cluster() method, but a figure without anything except a legend is returned. Everything works as expected after changing the linestring geometry to it's centroid point geometry. I guess that the linestring geometry is not supported perfectly enough?

The version of splot is 1.1.4

I checked it again and found it is caused by the fixed parameter values of linewidth=0.1 and edgecolor='white' of the plot() function in lisa_cluster(). As a result, all geometry of linestring will be invisable with a white backgroud at the same time.

Maybe it is better to do some adjust in source code with linestring geometry detected :)

As it's not convenient to set additional config I have to modify the source code (just remove the two fixed parameter values) as follow:

# original source code
# gdf.assign(cl=labels).plot(column='cl', categorical=True,
#                            k=2, cmap=hmap, linewidth=0.1, ax=ax,
#                            edgecolor='white', legend=legend,
#                            legend_kwds=legend_kwds, **kwargs)
gdf.assign(cl=labels).plot(column='cl', categorical=True,
                           k=2, cmap=hmap, ax=ax,
                           legend=legend,
                           legend_kwds=legend_kwds, **kwargs)
jGaboardi commented 2 years ago

@qizidog This has been fixed in main, but a fresh release has not yet been cut. See also #139, #140, and pysal/spaghetti#656.