Skip to content

Commit 047355f

Browse files
Add sphinx docs...
1 parent c98e671 commit 047355f

14 files changed

+347
-7
lines changed

.gitignore

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

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/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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
]
26+
27+
templates_path = ['_templates']
28+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
29+
30+
31+
# -- Options for HTML output -------------------------------------------------
32+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
33+
34+
html_theme = 'alabaster'
35+
html_static_path = ['_static']
36+
plot_include_source = True

docs/examples/index.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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.
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Examples:
12+
13+
plots/simplest_example
14+
plots/multiple_artist_view
15+
plots/simple_inset_view
16+
plots/sierpinski_triangle
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
A View With Several Plot Elements
2+
=================================
3+
4+
A simple example with an assortment of plot elements.
5+
6+
.. plot::
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()
30+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Sierpiński Triangle With Recursive Views
2+
========================================
3+
4+
Matplotview's views support recursive drawing of other views and themselves to a
5+
configurable depth. This feature allows matplotview to be used to generate fractals,
6+
such as a sierpiński triangle as shown in the following example.
7+
8+
.. plot::
9+
10+
import matplotlib.pyplot as plt
11+
import matplotview as mpv
12+
from matplotlib.patches import PathPatch
13+
from matplotlib.path import Path
14+
from matplotlib.transforms import Affine2D
15+
16+
# We'll plot a white upside down triangle inside of black one, and then use
17+
# 3 views to draw all the rest of the recursions of the sierpiński triangle.
18+
outside_color = "black"
19+
inner_color = "white"
20+
21+
t = Affine2D().scale(-0.5)
22+
23+
outer_triangle = Path.unit_regular_polygon(3)
24+
inner_triangle = t.transform_path(outer_triangle)
25+
b = outer_triangle.get_extents()
26+
27+
fig, ax = plt.subplots(1)
28+
ax.set_aspect(1)
29+
30+
ax.add_patch(PathPatch(outer_triangle, fc=outside_color, ec=[0] * 4))
31+
ax.add_patch(PathPatch(inner_triangle, fc=inner_color, ec=[0] * 4))
32+
ax.set_xlim(b.x0, b.x1)
33+
ax.set_ylim(b.y0, b.y1)
34+
35+
ax_locs = [
36+
[0, 0, 0.5, 0.5],
37+
[0.5, 0, 0.5, 0.5],
38+
[0.25, 0.5, 0.5, 0.5]
39+
]
40+
41+
for loc in ax_locs:
42+
inax = mpv.inset_zoom_axes(ax, loc, render_depth=6)
43+
inax.set_xlim(b.x0, b.x1)
44+
inax.set_ylim(b.y0, b.y1)
45+
inax.axis("off")
46+
inax.patch.set_visible(False)
47+
48+
fig.show()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Create Inset Axes Without Plotting Twice
2+
========================================
3+
4+
:meth:`matplotview.inset_zoom_axes` can be utilized to create inset axes where we
5+
don't have to plot the parent axes data twice.
6+
7+
.. plot::
8+
9+
from matplotlib import cbook
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
from matplotview import inset_zoom_axes
13+
14+
def get_demo_image():
15+
z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
16+
# z is a numpy array of 15x15
17+
return z, (-3, 4, -4, 3)
18+
19+
fig, ax = plt.subplots()
20+
21+
# Make the data...
22+
Z, extent = get_demo_image()
23+
Z2 = np.zeros((150, 150))
24+
ny, nx = Z.shape
25+
Z2[30:30+ny, 30:30+nx] = Z
26+
27+
ax.imshow(Z2, extent=extent, interpolation='nearest', origin="lower")
28+
29+
# Creates an inset axes with automatic view of the parent axes...
30+
axins = inset_zoom_axes(ax, [0.5, 0.5, 0.47, 0.47])
31+
# Set limits to sub region of the original image
32+
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
33+
axins.set_xlim(x1, x2)
34+
axins.set_ylim(y1, y2)
35+
36+
# Remove the tick labels from the inset axes
37+
axins.set_xticklabels([])
38+
axins.set_yticklabels([])
39+
40+
# Draw the indicator or zoom lines.
41+
ax.indicate_inset_zoom(axins, edgecolor="black")
42+
43+
fig.show()
44+
45+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The Simplest View
2+
=================
3+
4+
The simplest example: We make a view of a line! Views can be created quickly
5+
using :meth:`matplotview.view` .
6+
7+
.. plot::
8+
9+
from matplotview import view
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
13+
fig, (ax1, ax2) = plt.subplots(1, 2)
14+
15+
# Plot a line in the first axes.
16+
ax1.plot([i for i in range(10)], "-o")
17+
18+
# Create a view! Turn axes 2 into a view of axes 1.
19+
view(ax2, ax1)
20+
# Modify the second axes data limits so we get a slightly zoomed out view
21+
ax2.set_xlim(-5, 15)
22+
ax2.set_ylim(-5, 15)
23+
24+
fig.show()
25+

docs/index.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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:`modindex`
23+
* :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

0 commit comments

Comments
 (0)