38
38
class Circos :
39
39
"""Circos Visualization Class"""
40
40
41
+ # By default, after saving a figure using the `savefig()` method, figure object is
42
+ # automatically deleted to avoid memory leaks (no display on jupyter notebook)
43
+ # If you want to display the figure on jupyter notebook using `savefig()` method,
44
+ # set clear_savefig=False.
45
+ clear_savefig : bool = True
46
+
41
47
def __init__ (
42
48
self ,
43
49
sectors : Mapping [str , int | float | tuple [float , float ]],
@@ -522,8 +528,10 @@ def initialize_from_tree(
522
528
523
529
Returns
524
530
-------
525
- circos, tv : tuple[Circos, TreeViz]
526
- Circos & TreeViz instances initialized from tree
531
+ circos : Circos
532
+ Circos instance
533
+ tv : TreeViz
534
+ TreeViz instance
527
535
"""
528
536
# Initialize circos sector with tree size
529
537
tree = TreeViz .load_tree (tree_data , format = format )
@@ -946,7 +954,9 @@ def colorbar(
946
954
vmax : float = 1 ,
947
955
cmap : str | Colormap = "bwr" ,
948
956
orientation : str = "vertical" ,
957
+ label : str | None = None ,
949
958
colorbar_kws : dict [str , Any ] | None = None ,
959
+ label_kws : dict [str , Any ] | None = None ,
950
960
tick_kws : dict [str , Any ] | None = None ,
951
961
) -> None :
952
962
"""Plot colorbar
@@ -964,27 +974,35 @@ def colorbar(
964
974
<https://matplotlib.org/stable/tutorials/colors/colormaps.html>
965
975
orientation : str, optional
966
976
Colorbar orientation (`vertical`|`horizontal`)
977
+ label : str | None, optional
978
+ Colorbar label. If None, no label shown.
967
979
colorbar_kws : dict[str, Any] | None, optional
968
- Colorbar properties (e.g. `dict(label="name", format="%.1f", ...)`)
980
+ Colorbar properties (e.g. `dict(format="%.1f", ...)`)
969
981
<https://matplotlib.org/stable/api/colorbar_api.html>
982
+ label_kws : dict[str, Any] | None, optional
983
+ Text properties (e.g. `dict(size=15, color="red", ...)`)
984
+ <https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html>
970
985
tick_kws : dict[str, Any] | None, optional
971
986
Axes.tick_params properties (e.g. `dict(labelsize=12, colors="red", ...)`)
972
987
<https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.tick_params.html>
973
988
"""
974
989
colorbar_kws = {} if colorbar_kws is None else deepcopy (colorbar_kws )
990
+ label_kws = {} if label_kws is None else deepcopy (label_kws )
975
991
tick_kws = {} if tick_kws is None else deepcopy (tick_kws )
976
992
977
993
def plot_colorbar (ax : PolarAxes ) -> None :
978
994
axin : Axes = ax .inset_axes (bounds )
979
995
norm = Normalize (vmin = vmin , vmax = vmax )
980
- Colorbar (
996
+ cb = Colorbar (
981
997
axin ,
982
998
cmap = cmap , # type: ignore
983
999
norm = norm ,
984
1000
orientation = orientation , # type: ignore
985
1001
** colorbar_kws ,
986
1002
)
987
1003
axin .tick_params (** tick_kws )
1004
+ if label :
1005
+ cb .set_label (label , ** label_kws )
988
1006
989
1007
self ._plot_funcs .append (plot_colorbar )
990
1008
@@ -1055,9 +1073,6 @@ def savefig(
1055
1073
) -> None :
1056
1074
"""Save figure to file
1057
1075
1058
- `circos.savefig("result.png")` is alias for
1059
- `circos.plotfig().savefig("result.png")`
1060
-
1061
1076
Parameters
1062
1077
----------
1063
1078
savefile : str | Path
@@ -1068,6 +1083,11 @@ def savefig(
1068
1083
Figure size
1069
1084
pad_inches : float, optional
1070
1085
Padding inches
1086
+
1087
+ Warnings
1088
+ --------
1089
+ To plot a figure that settings a user-defined legend, subtracks, or annotations,
1090
+ call `fig.savefig()` instead of `gv.savefig()`.
1071
1091
"""
1072
1092
fig = self .plotfig (dpi = dpi , figsize = figsize )
1073
1093
fig .savefig (
@@ -1077,8 +1097,9 @@ def savefig(
1077
1097
bbox_inches = "tight" ,
1078
1098
)
1079
1099
# Clear & close figure to suppress memory leak
1080
- fig .clear ()
1081
- plt .close (fig )
1100
+ if self .clear_savefig :
1101
+ fig .clear ()
1102
+ plt .close (fig )
1082
1103
1083
1104
############################################################
1084
1105
# Private Method
@@ -1136,8 +1157,10 @@ def _initialize_figure(
1136
1157
1137
1158
Returns
1138
1159
-------
1139
- fig, ax : tuple[Figure, PolarAxes]
1140
- Figure, PolarAxes
1160
+ fig : Figure
1161
+ Figure
1162
+ ax : PolarAxes
1163
+ PolarAxes
1141
1164
"""
1142
1165
fig = plt .figure (figsize = figsize , dpi = dpi , tight_layout = True )
1143
1166
ax = fig .add_subplot (projection = "polar" )
0 commit comments