Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ponnhide committed May 13, 2023
2 parents 89fb7f9 + 20130c6 commit 19a2883
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
14 changes: 7 additions & 7 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,22 @@

#### Parameters

- `brick1`: patchworklib.Brick or patchworklib.Bricks class object
- `brick1`: patchworklib.Brick or patchworklib.Bricks class object
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
Brick(s) class object to be placed in specified in `brick1` object.
- `position`: str, (`"upper right"`, `"lower rigtht"`, `"upper left"`, `"lower left"`)
Position of `brick2` object in `brick1` object.
- `wratio`: float, default: 0.1
- `wratio`: float, default: 0.1
Ratio of the `brick2` width to `brick1` object.
- `hratio`: float, default: 0.1
- `hratio`: float, default: 0.1
Ratio of the `brick2` height to `brick1` object.
- `vmargin`: float, default: 0.1
- `vmargin`: float, default: 0.1
Margin from the bottom/top.
- `hmargin`: float, default: 0.1
- `hmargin`: float, default: 0.1
Margin from the right/left.
- `alpha`: flaot, default: 0.0
- `alpha`: flaot, default: 0.0
Alpha of background of `brick2` object

#### Returns
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If you want to use developmental version, it can be installed using the followin
- New operators, "+" and "-", were added.
- plotnine > v0.10.x is now supported.
- Plots generated by object-oriented seaborn interface can now be handled by patchworklib.
- Descriptions of each function and class provided in patchworklib is added to this repository. If you want to know the detailed usage of patchworklib, please see [API.md](https://github.com/ponnhide/patchworklib/blob/v0.5.0/API.md).
- Descriptions of each function and class provided in patchworklib was added to this repository. If you want to know how to use patchworklib in detail, please see [API.md](https://github.com/ponnhide/patchworklib/blob/main/API.md).
- Updated [patchworklib-examples](https://github.com/ponnhide/patchworklib-examples)

<details>
Expand Down Expand Up @@ -294,6 +294,8 @@ g1234.savefig()
</details>

## Usage
> _If you want to know how to use patchworklib in detail, please see [API.md](https://github.com/ponnhide/patchworklib/blob/main/API.md)._
>
Using `patchworklib`, you can quickly and freely arrange matplotlib plots with only `|` and `/` oparators as follows.

```python
Expand Down
7 changes: 2 additions & 5 deletions patchworklib/patchworklib.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,9 @@ def load_seabornobj(g, label=None, labels=None, figsize=(3,3)):
if len(g._subplots._subplot_list) > 1:
outers = bricks.get_inner_corner()
expand(bricks, figsize[0]/abs(outers[0]-outers[1]), figsize[1]/abs(outers[3]-outers[2]))

x0, x1, y0, y1 = bricks.get_outer_corner()
bricks._originalsize = (abs(x1-x0), abs(y0-y1))
if type(bricks) == Bricks:
x0, x1, y0, y1 = bricks.get_outer_corner()
bricks._originalsize = (abs(x1-x0), abs(y0-y1))
bricks.set_originalpositions()

return bricks

def load_seaborngrid(g, label=None, labels=None, figsize=None):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_patchworklib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path

import plotnine as p9
import seaborn as sns

import patchworklib as pw
Expand All @@ -25,3 +26,26 @@ def test_example_plot(tmp_path: Path):
ax12 = ax1 | ax2
ax12.savefig(result_file)
assert result_file.exists()


def test_sns_and_p9(tmp_path: Path):
titanic = sns.load_dataset("titanic")

g_sns = pw.Brick(figsize=(4, 4))
sns.boxplot(data=titanic, x="sex", y="survived", hue="class", ax=g_sns)
g_sns.set_title("seaborn")

g_p9 = pw.load_ggplot(
(
p9.ggplot(titanic, p9.aes(x="sex", y="survived", fill="class"))
+ p9.geom_boxplot()
+ p9.ggtitle("plotnine")
),
figsize=(4, 4),
)

g = g_sns | g_p9

result_file = tmp_path / "g.png"
g.savefig(result_file)
assert result_file.exists()

0 comments on commit 19a2883

Please sign in to comment.