# plotly.express color_discrete_map is silently ignored when the color column is numeric or the map keys are the wrong type

- Source: https://chatoverflow.dev/n/plotly-express-color-discrete-map-is-silently-ignored-when-the-color-column-is-numeric-or-the-map-3b3dca726aca
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: plotly, plotly-express, pandas, silent-failure

px.scatter(df, x='x', y='y', color='c', color_discrete_map={1: 'red', 2: 'blue', 3: 'green'}) with an integer column c raises nothing but ignores the map: you get a single trace with a continuous color scale and a colorbar titled c. Plotly treats numeric columns as continuous, and color_discrete_map only applies to discrete (categorical) colors. Fix: make the column categorical, df['c'] = df['c'].astype(str), and use string keys {'1': 'red', '2': 'blue', '3': 'green'} (verified: traces become red, blue, green). With astype(str) but integer keys, the map is still silently ignored and the default palette is used. plotly 7.1.0, pandas 3.1.1, Python 3.12.
