Skip to content

Commit 7a16896

Browse files
Merge pull request #1 from matplotlib/develop
Merge latest developments....
2 parents 06b66be + 02b77c1 commit 7a16896

28 files changed

+774
-145
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ result_images
55
.pytest_cache
66
dist
77
*.egg-info
8+
docs/_build/
9+
docs/api/generated
10+
docs/examples/

README.md

Lines changed: 5 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -12,118 +12,16 @@ You can install matplotview using pip:
1212
pip install matplotview
1313
```
1414

15-
## Usage
16-
17-
matplotview provides two methods, `view`, and `inset_zoom_axes`. The `view`
18-
method accepts two `Axes`, and makes the first axes a view of the second. The
19-
`inset_zoom_axes` method provides the same functionality as `Axes.inset_axes`,
20-
but the returned inset axes is configured to be a view of the parent axes.
21-
2215
## Examples
2316

24-
An example of two axes showing the same plot.
25-
```python
26-
from matplotview import view
27-
import matplotlib.pyplot as plt
28-
import numpy as np
29-
30-
fig, (ax1, ax2) = plt.subplots(1, 2)
31-
32-
# Plot a line, circle patch, some text, and an image...
33-
ax1.plot([i for i in range(10)], "r")
34-
ax1.add_patch(plt.Circle((3, 3), 1, ec="black", fc="blue"))
35-
ax1.text(10, 10, "Hello World!", size=20)
36-
ax1.imshow(np.random.rand(30, 30), origin="lower", cmap="Blues", alpha=0.5,
37-
interpolation="nearest")
38-
39-
# Turn axes 2 into a view of axes 1.
40-
view(ax2, ax1)
41-
# Modify the second axes data limits to match the first axes...
42-
ax2.set_aspect(ax1.get_aspect())
43-
ax2.set_xlim(ax1.get_xlim())
44-
ax2.set_ylim(ax1.get_ylim())
45-
46-
fig.tight_layout()
47-
fig.show()
48-
```
49-
![First example plot results, two views of the same plot.](https://user-images.githubusercontent.com/47544550/149814592-dd815f95-c3ef-406d-bd7e-504859c836bf.png)
50-
51-
An inset axes example.
52-
```python
53-
from matplotlib import cbook
54-
import matplotlib.pyplot as plt
55-
import numpy as np
56-
from matplotview import inset_zoom_axes
57-
58-
def get_demo_image():
59-
z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
60-
# z is a numpy array of 15x15
61-
return z, (-3, 4, -4, 3)
62-
63-
fig, ax = plt.subplots(figsize=[5, 4])
17+
Examples can be found in the example gallery:
6418

65-
# Make the data...
66-
Z, extent = get_demo_image()
67-
Z2 = np.zeros((150, 150))
68-
ny, nx = Z.shape
69-
Z2[30:30+ny, 30:30+nx] = Z
19+
[https://matplotview.readthedocs.io/en/latest/examples/index.html](https://matplotview.readthedocs.io/en/latest/examples/index.html)
7020

71-
ax.imshow(Z2, extent=extent, interpolation='nearest', origin="lower")
21+
## Documentation
7222

73-
# Creates an inset axes with automatic view of the parent axes...
74-
axins = inset_zoom_axes(ax, [0.5, 0.5, 0.47, 0.47])
75-
# Set limits to sub region of the original image
76-
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
77-
axins.set_xlim(x1, x2)
78-
axins.set_ylim(y1, y2)
79-
axins.set_xticklabels([])
80-
axins.set_yticklabels([])
23+
Additional documentation can be found at the link below:
8124

82-
ax.indicate_inset_zoom(axins, edgecolor="black")
25+
[https://matplotview.readthedocs.io/en/latest/](https://matplotview.readthedocs.io/en/latest/)
8326

84-
fig.show()
85-
```
86-
![Second example plot results, an inset axes showing a zoom view of an image.](https://user-images.githubusercontent.com/47544550/149814558-c2b1228d-2e5d-41be-86c0-f5dd01d42884.png)
87-
88-
Because views support recursive drawing, they can be used to create
89-
fractals also.
90-
```python
91-
import matplotlib.pyplot as plt
92-
import matplotview as mpv
93-
from matplotlib.patches import PathPatch
94-
from matplotlib.path import Path
95-
from matplotlib.transforms import Affine2D
96-
97-
outside_color = "black"
98-
inner_color = "white"
99-
100-
t = Affine2D().scale(-0.5)
101-
102-
outer_triangle = Path.unit_regular_polygon(3)
103-
inner_triangle = t.transform_path(outer_triangle)
104-
b = outer_triangle.get_extents()
10527

106-
fig, ax = plt.subplots(1)
107-
ax.set_aspect(1)
108-
109-
ax.add_patch(PathPatch(outer_triangle, fc=outside_color, ec=[0] * 4))
110-
ax.add_patch(PathPatch(inner_triangle, fc=inner_color, ec=[0] * 4))
111-
ax.set_xlim(b.x0, b.x1)
112-
ax.set_ylim(b.y0, b.y1)
113-
114-
ax_locs = [
115-
[0, 0, 0.5, 0.5],
116-
[0.5, 0, 0.5, 0.5],
117-
[0.25, 0.5, 0.5, 0.5]
118-
]
119-
120-
for loc in ax_locs:
121-
inax = mpv.inset_zoom_axes(ax, loc, render_depth=6)
122-
inax.set_xlim(b.x0, b.x1)
123-
inax.set_ylim(b.y0, b.y1)
124-
inax.axis("off")
125-
inax.patch.set_visible(False)
126-
127-
fig.show()
128-
```
129-
![Third example plot results, a Sierpiński triangle](https://user-images.githubusercontent.com/47544550/150047401-e9364f0f-becd-45c5-a6f4-062118ce713f.png)

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/_static/gallery_mods.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
.sphx-glr-thumbcontainer[tooltip]:hover:after {
3+
background: var(--sg-tooltip-background);
4+
-webkit-border-radius: 4px;
5+
-moz-border-radius: 4px;
6+
border-radius: 4px;
7+
color: var(--sg-tooltip-foreground);
8+
content: "";
9+
opacity: 0.35;
10+
padding: 10px;
11+
z-index: 98;
12+
width: 100%;
13+
height: 100%;
14+
position: absolute;
15+
pointer-events: none;
16+
top: 0;
17+
box-sizing: border-box;
18+
overflow: hidden;
19+
backdrop-filter: blur(3px);
20+
}

docs/api/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
API
2+
===
3+
4+
The public facing functions of matplotview.
5+
6+
.. autosummary::
7+
:toctree: generated
8+
9+
matplotview.view
10+
matplotview.stop_viewing
11+
matplotview.inset_zoom_axes
12+
13+

docs/conf.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from pathlib import Path
2+
import sys
3+
4+
# Add project root directory to python path...
5+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
6+
7+
8+
project = 'matplotview'
9+
copyright = '2022, Isaac Robinson'
10+
author = 'Isaac Robinson'
11+
release = '1.0.0'
12+
13+
# -- General configuration ---------------------------------------------------
14+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
15+
16+
extensions = [
17+
'sphinx.ext.autodoc',
18+
'sphinx.ext.autosummary',
19+
'sphinx.ext.doctest',
20+
'sphinx.ext.intersphinx',
21+
'sphinx.ext.viewcode',
22+
'numpydoc',
23+
'matplotlib.sphinxext.mathmpl',
24+
'matplotlib.sphinxext.plot_directive',
25+
'sphinx_gallery.gen_gallery'
26+
]
27+
28+
templates_path = ['_templates']
29+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
30+
31+
from sphinx_gallery.sorting import FileNameSortKey
32+
33+
sphinx_gallery_conf = {
34+
"examples_dirs": "../examples",
35+
"gallery_dirs": "examples",
36+
"line_numbers": True,
37+
"within_subsection_order": FileNameSortKey
38+
}
39+
40+
# -- Options for HTML output -------------------------------------------------
41+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
42+
43+
html_theme = 'alabaster'
44+
html_static_path = ['_static']
45+
html_css_files = ['gallery_mods.css']
46+
47+
plot_include_source = True

docs/index.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. matplotview documentation master file, created by
2+
sphinx-quickstart on Sat Aug 13 19:55:28 2022.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Matplotview |release| Documentation
7+
===================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
installation
14+
examples/index
15+
api/index
16+
17+
18+
Additional Links
19+
================
20+
21+
* :ref:`genindex`
22+
* :ref:`search`

docs/installation.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Installation
2+
============
3+
4+
Matplotview can be installed using `pip <https://pypi.org/project/matplotview>`__:
5+
6+
.. code-block:: bash
7+
8+
pip install matplotview
9+

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

examples/README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Examples
2+
========
3+
4+
Because of the way matplotview is designed, it can work with any Axes and projection
5+
types, and works with all the default projection modes included in matplotlib.
6+
The following examples showcase using matplotview in several different scenarios and
7+
with different projections.

examples/plot_00_simplest_example.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
The Simplest View
3+
=================
4+
5+
The simplest example: We make a view of a line! Views can be created quickly
6+
using :meth:`matplotview.view` .
7+
"""
8+
9+
from matplotview import view
10+
import matplotlib.pyplot as plt
11+
12+
fig, (ax1, ax2) = plt.subplots(1, 2)
13+
14+
# Plot a line in the first axes.
15+
ax1.plot([i for i in range(10)], "-o")
16+
17+
# Create a view! Turn axes 2 into a view of axes 1.
18+
view(ax2, ax1)
19+
# Modify the second axes data limits so we get a slightly zoomed out view
20+
ax2.set_xlim(-5, 15)
21+
ax2.set_ylim(-5, 15)
22+
23+
fig.show()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
A View With Several Plot Elements
3+
=================================
4+
5+
A simple example with an assortment of plot elements.
6+
"""
7+
8+
from matplotview import view
9+
import matplotlib.pyplot as plt
10+
import numpy as np
11+
12+
fig, (ax1, ax2) = plt.subplots(1, 2)
13+
14+
# Plot a line, circle patch, some text, and an image...
15+
ax1.plot([i for i in range(10)], "r")
16+
ax1.add_patch(plt.Circle((3, 3), 1, ec="black", fc="blue"))
17+
ax1.text(10, 10, "Hello World!", size=20)
18+
ax1.imshow(np.random.rand(30, 30), origin="lower", cmap="Blues", alpha=0.5,
19+
interpolation="nearest")
20+
21+
# Turn axes 2 into a view of axes 1.
22+
view(ax2, ax1)
23+
# Modify the second axes data limits to match the first axes...
24+
ax2.set_aspect(ax1.get_aspect())
25+
ax2.set_xlim(ax1.get_xlim())
26+
ax2.set_ylim(ax1.get_ylim())
27+
28+
fig.tight_layout()
29+
fig.show()

0 commit comments

Comments
 (0)