px.density_contour() ignores color labels for negative histfunc results
未关闭
还没有人认领这个 Issue。
bug
P3
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Consider the following example:
import plotly.express as px
import pandas as pd
import numpy as np
import plotly
np.random.seed(0)
n_samples = 1000
df = pd.DataFrame({
'x': np.random.randint(low=1, high=5, size=n_samples),
'y': np.random.randint(low=1, high=4, size=n_samples),
'z': np.random.normal(loc=-40, scale=20, size=n_samples),
})
df['z'] = df['z'] * df['x']
# uncomment to make some values above 0
# df['z'] = df['z'] + 80
# uncomment to make all values above 0
# df['z'] = df['z'].abs()
fig = px.density_contour(df, x='x', y='y', z='z', histfunc='avg', height=800, width=1200, title=f'Plotly version: {plotly.__version__}')
fig.update_traces(contours_coloring="fill", contours_showlabels=True)
fig.show()
It calculates average of mostly negative values, which results in the following plot:

Color bar has correct color range, but all data points use same color - yellow, which is not particularly useful. Similar situation happens when only part of data is negative (uncomment first commented line in the example):

Left (positive) section looks fine, while right (negative) is colored with only one color.
There are workarounds, that involve changing of input data, but this makes plot reading much harder.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先运行提供的 px.density_contour() 示例,使用负值和混合的 histfunc 结果,然后检查 density_contour 入口点以及等高线着色如何处理这些值。完成的标准是负值和混合结果使用完整的颜色范围,而不是折叠为单一颜色,同时现有的正值情况仍然正确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- numpy, pandas, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 65/100