@@ -522,31 +522,38 @@ def plot_matplotlib(
522522 parents = line ["parents" ]
523523 values = line ["values" ] * self ._xscale
524524 start_times = line ["start_times" ]
525-
525+
526526 # Calculate depth levels and positions
527527 n = len (labels )
528528 depths = np .zeros (n , dtype = int )
529529 if start_times is None :
530530 start_times = np .zeros (n )
531531 else :
532532 start_times = (start_times + self ._xshift ) * self ._xscale
533-
533+
534534 # Calculate depths based on parent relationships
535535 for i in range (n ):
536536 if parents [i ] is None :
537537 depths [i ] = 0
538538 else :
539- parent_idx = parents [i ] if isinstance (parents [i ], int ) else list (labels ).index (parents [i ])
539+ parent_idx = (
540+ parents [i ]
541+ if isinstance (parents [i ], int )
542+ else list (labels ).index (parents [i ])
543+ )
540544 depths [i ] = depths [parent_idx ] + 1
541-
545+
542546 # Draw rectangles for each frame
543547 import matplotlib .patches as mpatches
548+
544549 colormap = line ["kwargs" ].get ("colormap" , "viridis" )
545550 cmap = plt .get_cmap (colormap )
546551 max_depth = depths .max () + 1
547-
552+
548553 for i in range (n ):
549- color = cmap (depths [i ] / max_depth ) if max_depth > 1 else cmap (0.5 )
554+ color = (
555+ cmap (depths [i ] / max_depth ) if max_depth > 1 else cmap (0.5 )
556+ )
550557 rect = mpatches .Rectangle (
551558 (start_times [i ], depths [i ]),
552559 values [i ],
@@ -556,7 +563,7 @@ def plot_matplotlib(
556563 linewidth = 0.5 ,
557564 )
558565 ax .add_patch (rect )
559-
566+
560567 # Add label if rectangle is wide enough
561568 if values [i ] > 0.1 * (start_times .max () + values .max ()):
562569 ax .text (
@@ -566,9 +573,11 @@ def plot_matplotlib(
566573 ha = "center" ,
567574 va = "center" ,
568575 fontsize = 8 ,
569- color = "white" if depths [i ] / max_depth > 0.5 else "black" ,
576+ color = (
577+ "white" if depths [i ] / max_depth > 0.5 else "black"
578+ ),
570579 )
571-
580+
572581 ax .set_ylim (- 0.5 , max_depth )
573582 ax .set_ylabel ("Stack Depth" )
574583 elif line ["plot_type" ] == "fill_between" :
@@ -702,32 +711,36 @@ def plot_tikzfigure(self, layers=None, verbose: bool = False) -> TikzFigure:
702711 parents = line ["parents" ]
703712 values = line ["values" ] * self ._xscale
704713 start_times = line ["start_times" ]
705-
714+
706715 # Calculate depths
707716 n = len (labels )
708717 depths = np .zeros (n , dtype = int )
709718 if start_times is None :
710719 start_times = np .zeros (n )
711720 else :
712721 start_times = (start_times + self ._xshift ) * self ._xscale
713-
722+
714723 for i in range (n ):
715724 if parents [i ] is None :
716725 depths [i ] = 0
717726 else :
718- parent_idx = parents [i ] if isinstance (parents [i ], int ) else list (labels ).index (parents [i ])
727+ parent_idx = (
728+ parents [i ]
729+ if isinstance (parents [i ], int )
730+ else list (labels ).index (parents [i ])
731+ )
719732 depths [i ] = depths [parent_idx ] + 1
720-
733+
721734 # Draw rectangles for each frame
722735 bar_height = 0.8
723736 colors = ["red" , "blue" , "green" , "orange" , "purple" , "cyan" ]
724-
737+
725738 for i in range (n ):
726739 x_start = start_times [i ]
727740 x_end = start_times [i ] + values [i ]
728741 y_pos = depths [i ]
729742 color = colors [depths [i ] % len (colors )]
730-
743+
731744 rect_nodes = [
732745 [x_start , y_pos - bar_height / 2 ],
733746 [x_end , y_pos - bar_height / 2 ],
@@ -738,7 +751,11 @@ def plot_tikzfigure(self, layers=None, verbose: bool = False) -> TikzFigure:
738751 nodes = rect_nodes ,
739752 cycle = True ,
740753 fill = color ,
741- ** {k : v for k , v in line ["kwargs" ].items () if k != "colormap" },
754+ ** {
755+ k : v
756+ for k , v in line ["kwargs" ].items ()
757+ if k != "colormap"
758+ },
742759 )
743760 if verbose :
744761 print ("Generated TikZ figure:" )
@@ -896,48 +913,61 @@ def plotly_color(value):
896913 parents = line ["parents" ]
897914 values = np .asarray (line ["values" ]) * self ._xscale
898915 start_times = line ["start_times" ]
899-
916+
900917 # Calculate depths
901918 n = len (labels )
902919 depths = np .zeros (n , dtype = int )
903920 if start_times is None :
904921 start_times = np .zeros (n )
905922 else :
906923 start_times = tx (start_times )
907-
924+
908925 for i in range (n ):
909926 if parents [i ] is None :
910927 depths [i ] = 0
911928 else :
912- parent_idx = parents [i ] if isinstance (parents [i ], int ) else list (labels ).index (parents [i ])
929+ parent_idx = (
930+ parents [i ]
931+ if isinstance (parents [i ], int )
932+ else list (labels ).index (parents [i ])
933+ )
913934 depths [i ] = depths [parent_idx ] + 1
914-
935+
915936 # Create rectangles as shapes
916937 colormap = kwargs .get ("colormap" , "Viridis" )
917938 import plotly .express as px
918- colors = px .colors .sample_colorscale (colormap , np .linspace (0 , 1 , depths .max () + 1 ))
919-
939+
940+ colors = px .colors .sample_colorscale (
941+ colormap , np .linspace (0 , 1 , depths .max () + 1 )
942+ )
943+
920944 for i in range (n ):
921945 color = colors [depths [i ]] if depths .max () > 0 else colors [0 ]
922- shapes .append (dict (
923- type = "rect" ,
924- x0 = float (start_times [i ]),
925- x1 = float (start_times [i ] + values [i ]),
926- y0 = float (depths [i ]),
927- y1 = float (depths [i ] + 0.9 ),
928- fillcolor = color ,
929- line = dict (color = kwargs .get ("edgecolor" , "black" ), width = 0.5 ),
930- ))
931-
946+ shapes .append (
947+ dict (
948+ type = "rect" ,
949+ x0 = float (start_times [i ]),
950+ x1 = float (start_times [i ] + values [i ]),
951+ y0 = float (depths [i ]),
952+ y1 = float (depths [i ] + 0.9 ),
953+ fillcolor = color ,
954+ line = dict (
955+ color = kwargs .get ("edgecolor" , "black" ), width = 0.5
956+ ),
957+ )
958+ )
959+
932960 # Add text annotation if wide enough
933961 if values [i ] > 0.1 * (start_times .max () + values .max ()):
934- annotations .append (dict (
935- x = float (start_times [i ] + values [i ] / 2 ),
936- y = float (depths [i ] + 0.45 ),
937- text = labels [i ],
938- showarrow = False ,
939- font = dict (size = 8 , color = "white" ),
940- ))
962+ annotations .append (
963+ dict (
964+ x = float (start_times [i ] + values [i ] / 2 ),
965+ y = float (depths [i ] + 0.45 ),
966+ text = labels [i ],
967+ showarrow = False ,
968+ font = dict (size = 8 , color = "white" ),
969+ )
970+ )
941971 elif plot_type == "fill_between" :
942972 kwargs = line ["kwargs" ]
943973 x = tx (line ["x" ])
@@ -1725,43 +1755,47 @@ def plot_plotext(self, ax, layers=None):
17251755 parents = line ["parents" ]
17261756 values = (np .asarray (line ["values" ]) * self ._xscale ).tolist ()
17271757 start_times = line ["start_times" ]
1728-
1758+
17291759 # Calculate depths
17301760 n = len (labels )
17311761 depths = np .zeros (n , dtype = int )
17321762 if start_times is None :
17331763 start_times = np .zeros (n ).tolist ()
17341764 else :
17351765 start_times = self ._transform_x (line ["start_times" ]).tolist ()
1736-
1766+
17371767 for i in range (n ):
17381768 if parents [i ] is None :
17391769 depths [i ] = 0
17401770 else :
1741- parent_idx = parents [i ] if isinstance (parents [i ], int ) else list (labels ).index (parents [i ])
1771+ parent_idx = (
1772+ parents [i ]
1773+ if isinstance (parents [i ], int )
1774+ else list (labels ).index (parents [i ])
1775+ )
17421776 depths [i ] = depths [parent_idx ] + 1
1743-
1777+
17441778 # Draw bars for each frame
17451779 flame_kwargs = self ._plotext_bar_kwargs (kwargs )
17461780 flame_kwargs ["orientation" ] = "h"
1747-
1781+
17481782 # Use different colors for different depths
17491783 colormap = kwargs .get ("colormap" , "viridis" )
17501784 max_depth = int (depths .max ()) + 1
1751-
1785+
17521786 for i in range (n ):
17531787 # Simple color cycling based on depth
17541788 depth_colors = ["red" , "green" , "blue" , "yellow" , "cyan" , "magenta" ]
17551789 color = depth_colors [depths [i ] % len (depth_colors )]
1756-
1790+
17571791 ax .bar (
17581792 [start_times [i ] + values [i ] / 2 ],
17591793 [depths [i ]],
17601794 width = values [i ],
17611795 color = color ,
17621796 ** {k : v for k , v in flame_kwargs .items () if k != "color" },
17631797 )
1764-
1798+
17651799 legend_entries .append ((kwargs .get ("label" ), kwargs .get ("color" )))
17661800 elif plot_type == "fill_between" :
17671801 x = self ._transform_x (line ["x" ]).tolist ()
0 commit comments