@@ -50,6 +50,15 @@ def test_groups(fig: Figure, df_grouped: DataFrameGroupBy):
5050 return True
5151
5252
53+ def find_correct_column_order (cols , col_names ):
54+
55+ correctly_ordered_cols = []
56+ for col in col_names :
57+ if col in cols :
58+ correctly_ordered_cols .append (col )
59+ return correctly_ordered_cols
60+
61+
5362def find_grouping (
5463 fig : Figure , df_data : pd .DataFrame , cols : list [str ]
5564) -> tuple [DataFrameGroupBy , dict ]:
@@ -62,6 +71,7 @@ def find_grouping(
6271 f"marker_col/color_col/facet_col is misspecified because the specified dataframe grouping names { cols } don't match the names in the plotly figure { col_names } ." ,
6372 )
6473
74+ cols = find_correct_column_order (cols , col_names )
6575 df_grouped = df_data .groupby (cols )
6676
6777 str_groups = {}
@@ -77,16 +87,24 @@ def find_grouping(
7787 curve_name = ", " .join (str (x ) for x in curve_name )
7888 if "%{x}" in curve_name :
7989 unique_x_values = np .unique (data .x )
80- if len (unique_x_values ) == 1 :
90+ if len (unique_x_values ) == 1 and len ( data . x ) != 1 :
8191 curve_name = curve_name .replace ("%{x}" , str (unique_x_values [0 ]))
8292 else :
8393 curve_name = curve_name .replace (", %{x}" , "" )
8494 if "%{y}" in curve_name :
8595 unique_y_values = np .unique (data .y )
86- if len (unique_y_values ) == 1 :
96+ if len (unique_y_values ) == 1 and len ( data . y ) != 1 :
8797 curve_name = curve_name .replace ("%{y}" , str (unique_y_values [0 ]))
8898 else :
8999 curve_name = curve_name .replace (", %{y}" , "" )
100+ if "%{marker.size}" in curve_name :
101+ unique_size_values = np .unique (data .marker .size )
102+ if len (unique_size_values ) == 1 and len (data .marker .size ) != 1 :
103+ curve_name = curve_name .replace (
104+ "%{marker.size}" , str (unique_size_values [0 ])
105+ )
106+ else :
107+ curve_name = curve_name .replace (", %{marker.size}" , "" )
90108 curve_dict [index ] = str_groups [curve_name ]
91109
92110 return df_grouped , curve_dict
@@ -182,8 +200,6 @@ def add_molecules(
182200 name of the column in df that is used to color the datapoints in df - necessary when there is discrete conditional coloring (default None).
183201 symbol_col : str, optional
184202 name of the column in df that is used to determine the symbols of the datapoints in df (default None).
185- marker_col : str, optional
186- name of the column in df that is used to determine the marker shape of the datapoints in df (default None).
187203 facet_col : str, optional
188204 name of the column in df that is used to facet the data to multiple plots (default None).
189205 wrap : bool, optional
@@ -202,8 +218,6 @@ def add_molecules(
202218 df_data [color_col ] = df_data [color_col ].astype (str )
203219 if symbol_col is not None :
204220 df_data [symbol_col ] = df_data [symbol_col ].astype (str )
205- if marker_col is not None :
206- df_data [marker_col ] = df_data [marker_col ].astype (str )
207221 if facet_col is not None :
208222 df_data [facet_col ] = df_data [facet_col ].astype (str )
209223
@@ -214,8 +228,6 @@ def add_molecules(
214228
215229 if color_col is not None :
216230 cols .append (color_col )
217- if marker_col is not None :
218- cols .append (marker_col )
219231 if symbol_col is not None :
220232 cols .append (symbol_col )
221233 if facet_col is not None :
0 commit comments