splot icon indicating copy to clipboard operation
splot copied to clipboard

Is there a way to have the lowest alpha class visible?

Open Babakjfard opened this issue 4 years ago • 4 comments

My question is not a bug that may require fixing. Simply, I want to know if there is a way to prevent alpha makes complete fade out or 100% transparency? therefore prevent all polygons on first class will be invisible on the map. Am I losing something? Is there anyway that I can tell vba_choroplet to start from already second level, so that I can still see the values? Thank you for your help.

Babakjfard avatar Jul 29 '21 21:07 Babakjfard

I solved the problem this way. In file _viz_value_by_alpha_mpl.py I added this line inside value_by_alpha_cmap function after line 103:

rgba[:, 3] = np.maximum(rgba[:, 3], 0.1)

I think the best approach would be to add an optional value for minimum alpha when calling vba_choropleth and default be 0.

I think it would be good if you add this option. I can help with that by creating a new branch and send a pull request, if you consider adding this capability.

Babakjfard avatar Jul 30 '21 00:07 Babakjfard

Hello @Babakjfard, thank you for reporting this behaviour and suggesting this option! I agree it would be useful to add logic that allows to scale the alpha value used, or to display values better in certain bins.

I imagine two options:

A) the distribution of values in the rgbA array is currently normalised between 0 & 1, maybe another normalisation method would be better suited (i.e. custom between 0.1 & 1)

B) to introduce a threshold as suggested by @Babakjfard for low values.

I think the how to might need some discussion in the wider community, what are your thoughts @ljwolf @darribas @sjsrey ?

slumnitz avatar Aug 03 '21 10:08 slumnitz

A) the distribution of values in the rgbA array is currently normalised between 0 & 1, maybe another normalisation method would be better suited (i.e. custom between 0.1 & 1)

I can imagine similar keywords geopandas uses to normalise the colormap (vmin, vmax) so you can control this directly (both ends).

We could also reconsider the default behaviour here, I am not sure if the current one with alpha=0 is the best one.

martinfleis avatar Nov 16 '21 11:11 martinfleis

I solved the problem this way. In file _viz_value_by_alpha_mpl.py I added this line inside value_by_alpha_cmap function after line 103:

rgba[:, 3] = np.maximum(rgba[:, 3], 0.1)

I think the best approach would be to add an optional value for minimum alpha when calling vba_choropleth and default be 0.

I think it would be good if you add this option. I can help with that by creating a new branch and send a pull request, if you consider adding this capability.

Hi I encountered the same problem and used your method! It worked on the map but the legend is not reflecting the change and the first column is still transparent. Do you know anyway I can edit the legend?

ReichYang avatar Jun 08 '22 20:06 ReichYang