diff --git a/API.md b/API.md index ada8325..66a62db 100644 --- a/API.md +++ b/API.md @@ -6,8 +6,8 @@ #### Parameters - - `ggplot`: plotnine.ggplot.ggplot - - `figsize`: tuple (float, float), + - `ggplot`: plotnine.ggplot.ggplot + - `figsize`: tuple (float, float) Figure size. If it is not specified, the generated Bricks object would keep the original figure size of the given ggplot objecrt. @@ -38,15 +38,15 @@ #### Parameters - - `g`: `seaborn.axisgrid.xxGrid` object + - `g`: `seaborn.axisgrid.xxGrid` object A return value of the seaborn figure-level plotting functions such as relplot, distplot, catplot, jointplot and pairplot. - - `label`: str + - `label`: str Unique identifier for the `patchworklib.Brick(s)` class object to be returned. If you want to adjust a layout composed of multiple bricks object using the label indexing method, providing the unique label name for returned object should be encouraged. - - `figsize`: tuple (float, float) + - `figsize`: tuple (float, float) Figure size. If it is not specified, convert Bricks object would keep the original figure size of the given seaborn plot. @@ -68,15 +68,15 @@ #### Parameters - - `g`: seaborn.axisgrid.xxGrid object + - `g`: seaborn.axisgrid.xxGrid object A return value of the seaborn figure-level plotting functions such as relplot, distplot, catplot, jointplot and pairplot. - - `label`: str + - `label`: str Unique identifier for the `patchworklib.Brick(s)` class object to be returned. If you want to adjust a layout composed of multiple bricks object using the label indexing method, providing the unique label name for returned object should be encouraged. - - `figsize`: tuple (float, float) + - `figsize`: tuple (float, float) Figure size. If it is not specified, convert Bricks object would keep the original figure size of the given seaborn plot. @@ -95,33 +95,33 @@ #### Parameters - - `brick1`: patchworklib.Brick or patchworklib.Bricks class object + - `brick1`: patchworklib.Brick or patchworklib.Bricks class object A `patchworlib.Brick(s)` class object to be joined with `brick2` object. The location of this object is used as the base position for determining the `brick2` placement. - - `brick2`: patchworklib.Brick or patchworklib.Bricks class object + - `brick2`: patchworklib.Brick or patchworklib.Bricks class object A `patchworlib.Brick(s)` class object to be placed on the side specified by `direction` (by default, on the right side) of the `brick1` object. - - `target`: str, default: None, + - `target`: str, default: `None` Unique label name of the Brick or Brick(s) object that is a part of the `brick1` object. If you want to place `brick2` object next to the specific Brick(s) object in `brick1` object, please provide the `label` value of the Brick(s) object. - - `margin`: float or str (`"none"`), default: `None` + - `margin`: float or str (`"none"`), default: `None` Margin size between the two given Brick(s) objects. If `None`, the `pw.param["margin"]` value would be used as the margin size. If the value is `"none"`, two Brick(s) objects will be joined with no margin (meaning that the axes spines will be joined so that they are fully glued together). - - `direction`: str (`"r"` or `"l"`), default: `"r"` + - `direction`: str (`"r"` or `"l"`), default: `"r"` Side on which `brick2` is placed with respect to `brick1`. "r" means right. "l" means left. - - `adjust_height`: bool, default: True + - `adjust_height`: bool, default: `True` If `True`, the height of `brick2` object is adjusted so that it will be equal to the height of `brick1` object. - - `adjust_width`: bool, default: True + - `adjust_width`: bool, default: `True` If `True`, the width of `brick2` will be adjusted according to the aspect of `brick2` after stacking. If False, `brick2` will keep its original width after stacking. If `ajust_height` is `Fasle`, the value will also be `False`. - - `va`: str (`"top"` or `"bottom"`), default: `False` + - `va`: str (`"top"` or `"bottom"`), default: `False` If `adjsut_height` is `False`, the value will be effective. If the value is `"top"`, `brick2` object will be aligned to the left/right top of `brick1` object. If the value is `"bottom"`, `brick2` object will be aligned to the left/right bottom of `brick1` object. @@ -141,33 +141,33 @@ #### Parameters - - `brick1`: patchworklib.Brick or patchworklib.Bricks class object + - `brick1`: patchworklib.Brick or patchworklib.Bricks class object A `patchworlib.Brick(s)` class object to be joined with `brick2` object. The location of this object is used as the base position for determining the `brick2` placement. - - `brick2`: patchworklib.Brick or patchworklib.Bricks class object + - `brick2`: patchworklib.Brick or patchworklib.Bricks class object A `patchworlib.Brick(s)` class object to be placed on the side specified by `direction` (by default, on the top side) of the `brick1` object. - - `target`: str, default: None + - `target`: str, default: `None` Unique label name of the Brick or Brick(s) object that is a part of the `brick1` object. If you want to place `brick2` object next to the specific Brick(s) object in `brick1` object, please provide the `label` value of the Brick(s) object. - - `margin`: flaot, default: `pw.param["margin"]` + - `margin`: flaot, default: `pw.param["margin"]` Margin size between the two given Brick(s) objects. If `None`, the `pw.param["margin"]` value would be used as the margin size. If the value is `"none"`, two `patchworlib.Brick(s)` objects will be joined with no margin (meaning that the axes spines will be joined so that they are fully glued together). - - `direction`: str ("t" or "b"), default: "t" + - `direction`: str ("t" or "b"), default: `"t"` Side on which `brick2` is placed with respect to `brick1`. `"t"` means top, `"b"` means bottom. - - `adjust_height`: bool, default: True + - `adjust_height`: bool, default: `True` If True, the height of `brick2` will be adjusted according to the aspect of `brick2` after stacking. If False, `brick2` will keep its original height after stacking. If `ajust_width` is `Fasle`, the value will also be `False`. - - `adjust_width`: bool, default: True + - `adjust_width`: bool, default: `True` If `True`, the width of `brick2` object is adjusted so that it will be equal to the width of `brick1` object. - - `ha`: str ("left" or "right"), default: False + - `ha`: str ("left" or "right"), default: `False` If `adjsut_width` is `False`, the value will be effective. If the value is `"left"`, `brick2` object will be stacked on/below the left top/bottom of `brick1` object. If the value is `"right"`, `brick2` object will be stacked on/below the right top/bottom of `brick1` object. @@ -182,13 +182,13 @@ #### Parameters - - `bricks`: list of patchworklib.Brick(s) objects + - `bricks`: list of patchworklib.Brick(s) objects List composed of `patchworklib.Brick(s)` objects. The list can include both `patchworklib.Brick` and `patchworklib.Bricks` objects. - - `margin`: float, default: None + - `margin`: float, default: `None` Margin size of each Brick(s). If None, the `pw.param["margin"]` value would be used as the margin size between the Brick(s) objects. - - `operator`: str (`|`, `/`, `+`, or `-`), default: `|` + - `operator`: str (`|`, `/`, `+`, or `-`), default: `|` Orientation of the arrangement for the given `patchworklib.Brick(s)` object. If this value is `|` or `/`, the width/height of the object to be stacked will be adjusted so that it will be aligned with previous one. @@ -252,26 +252,26 @@ using `/`, `|`, `+`, and `-` operators. ### Parameters - - `bricks_dict`: dict + - `bricks_dict`: dict Dictionaly of `patchworklib.Brick(s)` objects. The label name of the Brick object is served as the dictionaly keys. - - `label`: str + - `label`: str Unique identifier for the Bricks class object. The value can be used in layout adjustment using label indexing. The value would be assigned to `self.label`. ### Attributes - - `case`: matplotlib.Axes.axes + - `case`: matplotlib.Axes.axes An invisible axes object surrounding Bricks object excluding common label, legend. - - `outline`: patchworklib.Bricks + - `outline`: patchworklib.Bricks A bricks object based on the invisible axes object surrounding all objects in the original Bricks object including `case` axes. - - `label`: str + - `label`: str Unique identifier of the Brick class object. If the Brick object is incorporated in the other super Bricks objects, the Brick object can be accessed from the super Bricks object by specifying the label name for the super object as `Bricks_object[{label}]`. - - `bricks_dict`: dict + - `bricks_dict`: dict Dictionary with labels of the Brick object as a dictionary key and the corresponding Brick object as a dictionary value. @@ -284,20 +284,16 @@ using `/`, `|`, `+`, and `-` operators. Set a index label on 'upper left' of the Bricks object. An index labels can be added, such as those on sub-figures published in scientific journals. - #### Parameters - - - `index`: str + #### Parameters + - `index`: str index value - - - `x`: float + - `x`: float By default, the value will be adjusted as index label is placed on 'upper left' of the Bricks object. - - - `y`: flaot, + - `y`: flaot By default, the value will be adjusted as index label is placed on 'upper left' of the Bricks object. - - - `args`: dict + - `args`: dict Text properties control the appearance of the label. #### Returns @@ -313,37 +309,29 @@ using `/`, `|`, `+`, and `-` operators. Set a colorbar for the Brick object and return a new Bricks object including the colorbar. ### Parameters - - - `cmap`: Colormap, default: `'viridis'` + - `cmap`: Colormap, default: `'viridis'` The colormap to use. - - - `x`: float, default: `None` + - `x`: float, default: `None` if `args['orientation']` is `'vertical'`, the value will be adjusted as the colorbar is placed on `'lower right'` of the Bricks object. if `args['orientation']` is `'horizontal'`, the value will be adjusted as the colorbar is placed on `'lower center'` of the Bricks object. The zero position for `x` is the most left axes of the Brick objects in the Bricks object. - - - `y`: float, default: `None` + - `y`: float, default: `None` if `args['orientation']` is `'vertical'`, the value will be adjusted as the colorbar is placed on `'lower right'` of the Bricks object. if `args['orientation']` is `'horizontal'`, the value will be adjusted as the colorbar is placed on 'lower center' of the Bricks object. The zero position for `y` is the most bottom axes of the Brick objects in the Bricks object. - - - `vmin`: float, default: `0` + - `vmin`: float, default: `0` Minimum value to anchor the colormap. - - - `vmax`: float, default: `1` + - `vmax`: float, default: `1` Maximum value to anchor the colormap. - - - `hratio`: float + - `hratio`: float Height ratio of colorbar to height of `self.case`. - - - `wratio`: float + - `wratio`: float Width ratio of colorbar to width of `self.case`. - - - `coordinate`: str (`"relative"` or `"absolute"`), default `"relative"` + - `coordinate`: str (`"relative"` or `"absolute"`), default `"relative"` If `"absolute"`, the values of x and y will mean the inches of the distances from the base zero positions. if `"relative"`, the values of `x` and `y` will mean the relative distances based on width and height of Bricks object from the base zero positions. @@ -357,11 +345,9 @@ using `/`, `|`, `+`, and `-` operators. Move legend ### Parameters - - - `new_lock`: str or int + - `new_lock`: str or int Location argument, as in matplotlib.axes.Axes.legend(). - - - `kws`: dict + - `kws`: dict Other keyword arguments can be used in matplotlib.axes.Axes.legend(). #### Returns @@ -403,25 +389,25 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` ### **Parameters** - - `bricks_dict`: dict + - `bricks_dict`: dict Dictionaly of patchworklib.Brick class objects. The label name of each Brick object is served as the dictionaly keys. - - `label`: str + - `label`: str Unique identifier for the Bricks class object. The value can be used in layout adjustment using label indexing. The value would be assigned to `self.label`. - ### **Attributes** - - `case`: matplotlib.Axes.axes + ### **Attributes** + - `case`: matplotlib.Axes.axes Invisible axes object surrounding Bricks object excluding common label, legend. - - `outline`: patchworklib.Bricks + - `outline`: patchworklib.Bricks A `patchworklib.Bricks` object based on the invisible axes object surrounding all objects in the original Bricks object including `case` axes. - - `label`: str + - `label`: str Unique identifier of the Bricks class object. If the Bricks object is incorporated in the other super Bricks objects, by specifying the label name for the super object as `Bricks_object[{label}]`, the Bricks object can be accessed from the super Bricks object. - - `bricks_dict`: dict + - `bricks_dict`: dict Dictionary with labels of the `patchworklib.Brick(s)` objects in the Bricks object as dictionary keys and the corresponding `patchworklib.Brick(s)` objects as dictionary values. @@ -434,11 +420,11 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` redundant labels and can add the common x axis label for all Brick(s) objects. #### Parameters - - `xlabel`: str + - `xlabel`: str xlabel value - - `labelpad`: int, default: 8 + - `labelpad`: int, default: `8` Spacing in points from the virtual axes bounding box of the Bricks object. - - `args`: dict + - `args`: dict Text properties control the appearance of the label. #### Returns @@ -454,13 +440,11 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` #### Parameters - - `ylabel`: str + - `ylabel`: str ylabel value - - - `labelpad`: int, default: 8 + - `labelpad`: int, default: `8` Spacing in points from the virtual axes bounding box of the Bricks object. - - - `args`: dict + - `args`: dict Text properties control the appearance of the label. #### Returns @@ -476,13 +460,13 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` #### Parameters - - `title`: str + - `title`: str title value - - `loc`: str ("center", "left", "right), default "center" - Which title to set. - - `pad`: int, default: 12 + - `loc`: str (`"center"`, `"left"`, `"right"`), default `"center"` + Which title to set. + - `pad`: int, default: `12` Spacing in points from the virtual axes bounding box of the Bricks object. - - `args`: dict + - `args`: dict Text properties control the appearance of the label. #### Returns @@ -496,16 +480,15 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` be added, such as those on sub-figures published in scientific journals. #### Parameters - - - `index`: str + - `index`: str index value - - `x`: float + - `x`: float By default, the value will be adjusted as index label is placed on 'upper left' of the Bricks object. - - `y`: flaot, + - `y`: flaot By default, the value will be adjusted as index label is placed on 'upper left' of the Bricks object. - - `args`: dict + - `args`: dict Text properties control the appearance of the label. **Returns** @@ -514,9 +497,6 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` - ### **`set_text(self, x, y, text, **args)`** - - - - ### **`set_supspine(self, which='left', visible=True, position=None, bounds=None)`** Set a common spine for the Bric(s) objects in the Bricks object. @@ -525,14 +505,14 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` #### Parameters - - `which`: str ('left', 'right', 'top', 'bottom'), default: 'left' + - `which`: str ('left', 'right', 'top', 'bottom'), default: `"left"` Kind of the spine - - `visible`: bool, default: True + - `visible`: bool, default: `True` Setting of Show/hide the spine - - `position`: tuple (position type ('outward', 'axes', 'data'), amount (float)), - Position of the spine. + - `position`: tuple (position type ('outward', 'axes', 'data'), amount (float)) + Position of the spine. For details, please see 'https://matplotlib.org/3.5.1/api/spines_api.html'. - - `bounds`: tuple (float, float), + - `bounds`: tuple (float, float) Bounds of the spine. For details, please see 'https://matplotlib.org/3.5.1/api/spines_api.html'. @@ -550,27 +530,27 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` - `cmap`: Colormap, default: `'viridis'` The colormap to use. - - `x`: float, default: None + - `x`: float, default: `None` if args['orientation'] is 'vertical', the value will be adjusted as the colorbar is placed on 'lower right' of the Bricks object. if args['orientation'] is 'horizontal', the value will be adjusted as the colorbar is placed on 'lower center' of the Bricks object. The zero position for `x` is the most left axes of the Brick objects in the Bricks object. - - `y`: float, default: `None` + - `y`: float, default: `None` if args['orientation'] is 'vertical', the value will be adjusted as the colorbar is placed on 'lower right' of the Bricks object. if args['orientation'] is 'horizontal', the value will be adjusted as the colorbar is placed on 'lower center' of the Bricks object. The zero position for `y` is the most bottom axes of the Brick objects in the Bricks object. - - `vmin`: float, default: `0` + - `vmin`: float, default: `0` Minimum value to anchor the colormap. - - `vmax`: float, default: `1` + - `vmax`: float, default: `1` Maximum value to anchor the colormap. - - `hratio`: float + - `hratio`: float Height ratio of colorbar to height of `self.case` - - `wratio`: float + - `wratio`: float Width ratio of colorbar to width of `self.case` - - `coordinate`: str ("relative", "absolute"), default "relative" + - `coordinate`: str ("relative", "absolute"), default: `"relative"` if "absolute", the values of x and y will mean the inches of the distances from the base zero positions. if "relative", the values of x and y will mean the relative distances based on width and height of Bricks object from the base zero positions. @@ -584,10 +564,9 @@ It can be joined with aother `patchworklib.Brick(s)` object by using `/`, `|`, ` Move legend. #### Parameters - - - `new_lock`: str or int + - `new_lock`: str or int Location argument, as in matplotlib.axes.Axes.legend(). - - `kws`: dict + - `kws`: dict Other keyword arguments can be used in matplotlib.axes.Axes.legend(). #### Returns diff --git a/patchworklib/__init__.py b/patchworklib/__init__.py index 247adee..12eada1 100644 --- a/patchworklib/__init__.py +++ b/patchworklib/__init__.py @@ -1,2 +1,2 @@ from .patchworklib import * -__version__ = "0.5.1" +__version__ = "0.5.2" diff --git a/patchworklib/patchworklib.py b/patchworklib/patchworklib.py index d305c11..02fb160 100644 --- a/patchworklib/patchworklib.py +++ b/patchworklib/patchworklib.py @@ -46,7 +46,7 @@ matplotlib.rcParams['xtick.major.size'] = 4 matplotlib.rcParams['ytick.major.size'] = 4 -__version__ = "0.5.1" +__version__ = "0.5.2" _basefigure = plt.figure(figsize=(1,1)) _render = _basefigure.canvas.get_renderer() _scale = Affine2D().scale(1./_basefigure.dpi) @@ -170,7 +170,13 @@ def _reset_ggplot_legend(bricks): """ if "_ggplot_legend" in bricks.__dict__ and bricks._ggplot_legend is not None: - bricks._case.artists.remove(bricks._ggplot_legend) + if (matplotlib.__version__) >= StrictVersion("3.7"): + for tmp_artist in bricks._case.artists: + if tmp_artist == bricks._ggplot_legend: + tmp_artist.remove() + else: + bricks._case.artists.remove(bricks._ggplot_legend) + anchored_box = AnchoredOffsetbox( loc=bricks._ggplot_legend_loc, child=bricks._ggplot_legend_box, diff --git a/setup.py b/setup.py index 5dfa3d5..263185e 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ URL = 'https://github.com/ponnhide/patchworklib' LICENSE = 'GNU General Public License v3.0' DOWNLOAD_URL = 'https://github.com/ponnhide/patchworklib' -VERSION = '0.5.1' +VERSION = '0.5.2' PYTHON_REQUIRES = ">=3.7" INSTALL_REQUIRES = [