Hi there,
I am trying to do a scatter plot with plotly_express and I want to assign different colors and symbols based on the columns of my DataFrame. The problem is that only around 4 symbols are used and I have more than 20 cathegories. The values in the column for different colors that I am referencing are strings with different organ names, e.g.: [“stomach”, “heart”, “liver”, “lungs”, …]. The column that I am referencing for the symbols contains strings with values like [“P001”, “P015”, “P009”, …]. I also tried passing a list of integer values depending on the organ name but it still did not work. Below I share the core I am using. Also I add a picture of how it looks for me.
fig = px.scatter(df_manifold, x=x_col, y=y_col, color=c_col, title=f"{title_prefix} of multi organ database",
color_discrete_sequence=my_color_palette, category_orders=category_order, symbol="replicate")
df_manifold
is a data frame with columns: [x_col, y_col, c_col, "replicate"]
. c_col
and replicate
are the columbs for the color and symbol respectively.
Solution:
I solved it now by passing together symbol_map
which is a dictionary mapping from the values of the column to symbol codes that Plotly can interpret. For a list of symbols look at the end of this page: https://plotly.com/python/marker-style/
I solved it now by passing together symbol_map
which is a dictionary mapping from the values of the column to symbol codes that Plotly can interpret. For a list of symbols look at the end of this page: https://plotly.com/python/marker-style/
Hi Leonardo,
I am facing a similar problem but cant get it this symbols_map
dict to work for my dataframe with 3 cols Profit, Volume and WinningFactor where the first two cols are float and the last is str (containing 3 class labels).
Issue posted here: Changing marker symbols on px.scatter
Hi diliprk,
I think you just need to specify where the symbol comes from in your data, something like symbol="column-name"
1 Like
Hey, I know this is a while back but when and use the marker styles in Styling markers in Python I get the following error. If I limit my symbols to that small set, it works but if I try and use some of the more “fancy” symbols (from the link) raise that error. Thoughts?
ValueError:
Invalid value of type ‘builtins.str’ received for the ‘symbol’ property of scatter3d.marker
Received value: ‘pentagon’
The 'symbol' property is an enumeration that may be specified as:
- One of the following enumeration values:
['circle', 'circle-open', 'cross', 'diamond',
'diamond-open', 'square', 'square-open', 'x']
- A tuple, list, or one-dimensional numpy array of the above
Yes, scatter_3d
and scatter_gl
support a smaller set of symbols than scatter
.
1 Like