python-visualization / python-visualization/branca

Different sets of colors with to_step() versus StepColormap() when using a list of custom bins

Đang mở
#172 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
134
Fork
69
Merge trung bình
1 giờ 10 phút
Pull request đã merge (30 ngày)
1

Mô tả

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

I'm finding that, when using a set of custom bins within a colormap, the color palette generated with to_step() differs from that created via StepColormap(), even though both of these methods produce the same palette when custom bins are not requested.

Code that demonstrates this discrepancy can be found within this notebook.

Expected behavior

I would expect that the color palettes generated via the following code would be the same: (I recognize that the range represented by each color will change due to the use of custom bins, but I was expecting the actual colors to remain unmodified).

Method 1:
linear_to_step = linear.RdYlBu_10.to_step(n = 10)

Output:

image

Method 2:

bins = [-26.57727350868145,
 -2.8124548451811697,
 -1.3842847014410304,
 -0.57942086570913,
 0.10509734758955473,
 0.803350933220706,
 1.5648502030833924,
 2.497913057064161,
 3.8660584451404807,
 5.966706571952004,
 25.59683979436641]

custom_bins_to_step = linear.RdYlBu_10.to_step(index = bins)
Output:
image

Note that, when the second method is used, the interior colors within the color palette get much lighter, though the first and last colors are the same. (See the notebook I linked to earlier for a list of the colors.)

Meanwhile, the following methods that use StepColormap produce the same palettes:

Method 1:
color_range = color_brewer('RdYlBu', n = 10)
linear_stepcolormap = StepColormap(colors = color_range)
Output:

image

Method 2 (using previously defined color_range and bins values):

custom_bins_stepcolormap = StepColormap(
    colors = color_range, 
    vmin = bins[0], vmax = bins[-1],
    index = bins)

Output:
image

I'm not sure whether this is a bug or if I'm misunderstanding how the to_step() method works, but either way, your help in getting to_step() to produce the same color palette with custom bins that it does without custom bins would be greatly appreciated. I would also be happy to test out any potential fixes/solutions.

Environment:

  • Browser [e.g. chrome, firefox]: Running this code via JupyterLab Desktop and Visual Studio Code. Currently writing this on Chrome
  • Jupyter Notebook or html files? Jupyter Notebook
  • Python version: 3.12.3
  • folium version: 0.16.0
  • branca version: 0.7.2

Additional context

When custom_bins_to_step and custom_bins_stepcolormap are fed into the same custom choropleth mapping function, they produce very different results:

Map created with custom_bins_stepcolormap:

image

The colors in the above map match those I'm seeing from a folium.Choropleth() call.

Map created with custom_bins_to_step):

image

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với notebook Mapping/colormap_tests.ipynb được liên kết và so sánh các palette từ linear.RdYlBu_10.to_step(index=bins) và StepColormap(colors=color_range, index=bins). Theo dõi cách to_step() và StepColormap() xử lý các bins tùy chỉnh, sau đó xác minh rằng cả hai tạo ra cùng các màu cho các bins được cung cấp trong khi vẫn giữ nguyên các phạm vi của chúng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
jupyter-notebook, python
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.