@@ -264,7 +264,7 @@ def _handle_color_dict(self, colors: dict[str, str], labels: list[str]) -> list[
264264 return self ._generate_colors_from_colormap (self .default_colormap , len (labels ))
265265
266266 # Find missing labels
267- missing_labels = set (labels ) - set (colors .keys ())
267+ missing_labels = sorted ( set (labels ) - set (colors .keys () ))
268268 if missing_labels :
269269 logger .warning (
270270 f'Some labels have no color specified: { missing_labels } . Using { self .default_colormap } for these.'
@@ -354,7 +354,8 @@ def with_plotly(
354354 Returns:
355355 A Plotly figure object containing the generated plot.
356356 """
357- assert mode in ['bar' , 'line' , 'area' ], f"'mode' must be one of { ['bar' , 'line' , 'area' ]} "
357+ if mode not in ('bar' , 'line' , 'area' ):
358+ raise ValueError (f"'mode' must be one of {{'bar','line','area'}}, got { mode !r} " )
358359 if data .empty :
359360 return go .Figure ()
360361
@@ -500,7 +501,8 @@ def with_matplotlib(
500501 - If `mode` is 'line', stepped lines are drawn for each data series.
501502 - The legend is placed below the plot to accommodate multiple data series.
502503 """
503- assert mode in ['bar' , 'line' ], f"'mode' must be one of { ['bar' , 'line' ]} for matplotlib"
504+ if mode not in ('bar' , 'line' ):
505+ raise ValueError (f"'mode' must be one of {{'bar','line'}} for matplotlib, got { mode !r} " )
504506
505507 if fig is None or ax is None :
506508 fig , ax = plt .subplots (figsize = figsize )
@@ -595,7 +597,7 @@ def heat_map_matplotlib(
595597
596598 # Create the heatmap plot
597599 fig , ax = plt .subplots (figsize = figsize )
598- ax .pcolormesh (data .values , cmap = color_map )
600+ ax .pcolormesh (data .values , cmap = color_map , shading = 'auto' )
599601 ax .invert_yaxis () # Flip the y-axis to start at the top
600602
601603 # Adjust ticks and labels for x and y axes
@@ -615,7 +617,7 @@ def heat_map_matplotlib(
615617
616618 # Add the colorbar
617619 sm1 = plt .cm .ScalarMappable (cmap = color_map , norm = plt .Normalize (vmin = color_bar_min , vmax = color_bar_max ))
618- sm1 ._A = []
620+ sm1 .set_array ([])
619621 fig .colorbar (sm1 , ax = ax , pad = 0.12 , aspect = 15 , fraction = 0.2 , orientation = 'horizontal' )
620622
621623 fig .tight_layout ()
@@ -772,6 +774,8 @@ def heat_map_data_from_df(
772774 ('h' , 'min' ): ('%Y-%m-%d %H:00' , '%M' ), # minute of hour
773775 }
774776
777+ if df .empty :
778+ raise ValueError ('DataFrame is empty.' )
775779 diffs = df .index .to_series ().diff ().dropna ()
776780 minimum_time_diff_in_min = diffs .min ().total_seconds () / 60
777781 time_intervals = {'min' : 1 , '15min' : 15 , 'h' : 60 , 'D' : 24 * 60 , 'W' : 7 * 24 * 60 }
@@ -783,7 +787,8 @@ def heat_map_data_from_df(
783787
784788 # Select the format based on the `periods` and `steps_per_period` combination
785789 format_pair = (periods , steps_per_period )
786- assert format_pair in formats , f'{ format_pair } is not a valid format. Choose from { list (formats .keys ())} '
790+ if format_pair not in formats :
791+ raise ValueError (f'{ format_pair } is not a valid format. Choose from { list (formats .keys ())} ' )
787792 period_format , step_format = formats [format_pair ]
788793
789794 df = df .sort_index () # Ensure DataFrame is sorted by time index
@@ -950,7 +955,7 @@ def pie_with_plotly(
950955 values = data_sum .values .tolist ()
951956
952957 # Apply color mapping using the unified color processor
953- processed_colors = ColorProcessor (engine = 'plotly' ).process_colors (colors , list ( data . columns ) )
958+ processed_colors = ColorProcessor (engine = 'plotly' ).process_colors (colors , labels )
954959
955960 # Create figure if not provided
956961 fig = fig if fig is not None else go .Figure ()
@@ -1119,7 +1124,7 @@ def dual_pie_with_plotly(
11191124 title: The main title of the plot.
11201125 subtitles: Tuple containing the subtitles for (left, right) charts.
11211126 legend_title: The title for the legend.
1122- hole: Size of the hole as a fraction of the radius (0.0– 1.0).
1127+ hole: Size of the hole in the center for creating donut charts (0.0 to 1.0).
11231128 lower_percentage_group: Group segments whose cumulative share is below this percentage (0–100) into "Other".
11241129 hover_template: Template for hover text. Use %{label}, %{value}, %{percent}.
11251130 text_info: What to show on pie segments: 'label', 'percent', 'value', 'label+percent',
@@ -1441,8 +1446,9 @@ def export_figure(
14411446
14421447 if isinstance (figure_like , plotly .graph_objs .Figure ):
14431448 fig = figure_like
1444- if not filename .suffix == '.html' :
1445- logger .debug (f'To save a plotly figure, the filename should end with ".html". Got { filename } ' )
1449+ if filename .suffix != '.html' :
1450+ logger .warning (f'To save a Plotly figure, using .html. Adjusting suffix for { filename } ' )
1451+ filename = filename .with_suffix ('.html' )
14461452 if show and not save :
14471453 fig .show ()
14481454 elif save and show :
0 commit comments