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

BUG: explore() using cmap instead of color attribute for *list-like of colors* when if column and categorical is set #3194

Open
3 tasks done
turbotimon opened this issue Feb 20, 2024 · 4 comments
Labels

Comments

@turbotimon
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of geopandas.

  • (optional) I have confirmed this bug exists on the main branch of geopandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import geopandas as gpd
data = {"type": "FeatureCollection", "features": [{"id": "1006", "type": "Feature", "properties": {"cluster": 1}, "geometry": {"type": "Point", "coordinates": [8.20894, 47.48112]}}, {"id": "1012", "type": "Feature", "properties": {"cluster": 0}, "geometry": {"type": "Point", "coordinates": [9.43357, 47.51026]}}, {"id": "1019", "type": "Feature", "properties": {"cluster": 1}, "geometry": {"type": "Point", "coordinates": [7.5748328, 47.5686935]}}, {"id": "1024", "type": "Feature", "properties": {"cluster": 2}, "geometry": {"type": "Point", "coordinates": [9.03017, 46.1963]}}, {"id": "1025", "type": "Feature", "properties": {"cluster": 2}, "geometry": {"type": "Point", "coordinates": [7.99028, 46.31906]}}]}
gdf = gpd.GeoDataFrame.from_features(data["features"])

# Plot
gdf.explore(
    column="cluster",
    categorical=True,
    legend=True,
    color=["red", "green", "blue"], # does not work, despite docs say so
    # cmap=["red", "green", "blue"], # works, but not in the docs
)

Problem description

I was trying to set colors for a categorical plot but was not able doing so with colors (list-like of colors) as the docs say.
Instead, after inspecting the source code, I saw that it is possible passing the list as cmap. BUT, this is not in the docs (only says str, matplotlib.Colormap, branca.colormap or function)

Recomendation

  • Either: being able to pass list-like of colors with colors
  • Or: Adding to the docs for cmap: str, matplotlib.Colormap, branca.colormap, function or array-like

Happy to do a MR for both (whatever you choose). However, in my opinion colors would be more consistent and intuitive.

Output of geopandas.show_versions()

SYSTEM INFO

python : 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
executable : /usr/bin/python3
machine : Linux-6.1.58+-x86_64-with-glibc2.35

GEOS, GDAL, PROJ INFO

GEOS : 3.11.2
GEOS lib : None
GDAL : 3.6.4
GDAL data dir: /usr/local/lib/python3.10/dist-packages/fiona/gdal_data
PROJ : 9.3.0
PROJ data dir: /usr/local/lib/python3.10/dist-packages/pyproj/proj_dir/share/proj

PYTHON DEPENDENCIES

geopandas : 0.13.2
numpy : 1.25.2
pandas : 1.5.3
pyproj : 3.6.1
shapely : 2.0.2
fiona : 1.9.5
geoalchemy2: None
geopy : 2.3.0
matplotlib : 3.7.1
mapclassify: 2.6.1
pygeos : None
pyogrio : None
psycopg2 : 2.9.9 (dt dec pq3 ext lo64)
pyarrow : 10.0.1
rtree : None

@m-richards
Copy link
Member

Thanks for reporting this @turbotimon, I'll let @martinfleis suggest what the best option is in terms of merging into one keyword or supporting both properly as currently documented.

@martinfleis
Copy link
Member

cmap works by accident and color does not work together with column. It is one or the other, we should probably document that better. We also should support mapping of colours to values in some way but that hasn't been implemented yet. It is part of the plotting refactoring project that is on the roadmap for 1.x release once 1.0 is out.

@turbotimon
Copy link
Author

turbotimon commented Feb 29, 2024

color does not work together with column

I hope this is not intentional and also included in the plotting refactoring? As in my copy-paste example, it is very helpful to pass a list of colors along with a categorical column to give the categories a meaningful or more visible color compared to the map background.

Anyway, let me know if I can help with something.

@martinfleis
Copy link
Member

column should be used together with cmap to assign colours to values. color should be used alone to simply assign a color to a geometry. Not ideal, I'm aware.

The refactoring is not planned in detail yet but this use case will surely be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants