px.density_contour() ignores color labels for negative histfunc results
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 18.8k
- Forks
- 2.8k
- Ø Merge
- 16 Std. 26 Min.
- Gemergte PRs (30 T.)
- 21
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das bereitgestellte px.density_contour()-Beispiel mit negativen und gemischten histfunc-Ergebnissen auszuführen, und untersuche dann den density_contour-Einstiegspunkt sowie, wie die Konturfärbung mit diesen Werten umgeht. Erledigt ist es, wenn negative und gemischte Ergebnisse den vollständigen Farbbereich verwenden, statt auf eine Farbe zusammenzufallen, während der bestehende positive Fall weiterhin korrekt bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- numpy, pandas, python
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 65/100