Skip to content

Commit

Permalink
add tests and docs for text annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter committed May 31, 2024
1 parent e1da192 commit f78151f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ for ax in bax.axs:

![datetime_example](https://raw.githubusercontent.com/bendichter/brokenaxes/master/datetime_example.png)

### text annotation
```python
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes

fig = plt.figure(figsize=(5, 5))
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1))
)
bax.text(0.5, 0.5, "hello")
```


## How do I do more?
You can customize brokenaxes outside of the supported features listed above. Brokenaxes works by creating a number of smaller axes objects, with the positions and sizes of those axes dictated by the data ranges used in the constructor. Those individual axes are stored as a list in `bax.axs`. Most customizations will require accessing those inner axes objects. (See the last two lines of [the datetime example](https://github.com/bendichter/brokenaxes#datetime)). There is also a larger invisible axes object, `bax.big_ax`, which spans the entire brokenaxes region and is used for things like x and y axis labels which span all of the smaller axes.
Expand All @@ -144,6 +156,6 @@ brokenaxes uses `pytest-mpl` to ensure that the plots are created correctly.

To test that the plots are created correctly, run `pytest --mpl --mpl-baseline-path test_baseline test.py` from the root directory.

To generate new test plots, run `pytest --mpl-generate-path tests_baseline test.py` from the root directory.
To generate new test plots, run `pytest --mpl-generate-path test_baseline test.py` from the root directory.

If you are running the tests on a headless server, you may need to set the MPLBACKEND environment variable to Agg.
9 changes: 9 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ def test_secondary_axes():
return fig


@pytest.mark.mpl_image_compare
def test_text():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)))
bax.text(0.5, 0.5, "hello")

return fig


@pytest.mark.mpl_image_compare
def test_draw_diags():
fig = plt.figure(figsize=(5, 2))
Expand Down
Binary file removed test_baseline/test_text.png
Binary file not shown.

0 comments on commit f78151f

Please sign in to comment.