domplotlib¶
Dom’s extensions to matplotlib
Installation¶
python3 -m pip install domplotlib --user
python3 -m pip install git+https://github.com/domdfcoding/domplotlib@master --user
Contents¶
domplotlib
¶
Dom’s extensions to matplotlib.
Functions:
|
Creates a figure with the given margins, and returns a tuple of the figure and its axes. |
|
Place a legend on the figure, with the items arranged to read right to left rather than top to bottom. |
|
Save the given figure as an SVG. |
|
Transposes the contents of |
-
create_figure
(pagesize, left=0.2, bottom=0.14, right=0.025, top=0.13)[source]¶ Creates a figure with the given margins, and returns a tuple of the figure and its axes.
-
horizontal_legend
(fig, handles=None, labels=None, *, ncol=1, **kwargs)[source]¶ Place a legend on the figure, with the items arranged to read right to left rather than top to bottom.
- Parameters
- Return type
-
save_svg
(figure, fname, *, dpi=None, facecolor='w', edgecolor='w', orientation='portrait', transparent=False, bbox_inches=None, pad_inches=0.1, **kwargs)[source]¶ Save the given figure as an SVG.
- Parameters
figure (
Figure
)fname (
Union
[str
,Path
,PathLike
,IO
]) –The file to save the SVG as. If
format
is set, it determines the output format, and the file is saved asfname
. Note thatfname
is used verbatim, and there is no attempt to make the extension, if any, offname
matchformat
, and no extension is appended.If
format
is not set, then the format is inferred from the extension offname
, if there is one.dpi (
Union
[float
,Literal
['figure'
],None
]) – The resolution in dots per inch. If'figure'
, use the figure’s dpi value. DefaultNone
.facecolor (
Union
[str
,Literal
['auto'
]]) – The facecolor of the figure. If'auto'
, use the current figure facecolor. Default'w'
.edgecolor (
Union
[str
,Literal
['auto'
]]) – The edgecolor of the figure. If'auto'
, use the current figure edgecolor. Default'w'
.orientation (
Literal
['portrait'
,'landscape'
]) – Currently only supported by the postscript backend. Default'portrait'
.transparent (
bool
) – IfTrue
, the axes patches will all be transparent; the figure patch will also be transparent unlessfacecolor
and/oredgecolor
are specified. This is useful, for example, for displaying a plot on top of a colored background on a web page. The transparency of these patches will be restored to their original values upon exit of this function. DefaultFalse
.bbox_inches (
Optional
[str
]) – Bounding box in inches: only the given portion of the figure is saved. If ‘tight’, try to figure out the tight bbox of the figure. DefaultNone
.pad_inches (
float
) – Amount of padding around the figure when bbox_inches is ‘tight’. Default0.1
.**kwargs – Additional keyword arguments passed to
savefig()
.
domplotlib.plots
¶
Custom plotting functions.
New in version 0.2.0.
Functions:
|
Construct a pie chart from |
-
pie_from_tally
(tally, explode=(), *, percent=False, reverse=False, autopct=None, **kwargs)[source]¶ Construct a pie chart from
cawdrey.tally.Tally
.- Parameters
explode (
Collection
[str
]) – A list of key names to explode the segments for. Default()
.percent (
bool
) – IfTrue
, shows the percentage of each element out of the sum of all elements. DefaultFalse
.reverse (
bool
) – Order the wedges clockwise rather than anticlockwise.. DefaultFalse
.**kwargs – Other keyword arguments taken by
matplotlib.axes.Axes.pie()
.
- Return type
- Returns
- Overloads
domplotlib.styles
¶
Each of these styles expose plt
, which is an alias of matplotlib.pyplot
. Importing one of these styles configures matplotlib to use the desired style.
The styles currently available are:
default
– The default matplotlib style. Forces the backend to beTkAgg
iftkinter
is available.domdf
– A theme adapted fromSolarize_Light2
.
Note
Importing a style for a second time will not change the current style.
Use importlib.reload()
to reload the module after importing to ensure the style is correctly set.
Overview¶
domplotlib
uses tox to automate testing and packaging,
and pre-commit to maintain code quality.
Install pre-commit
with pip
and install the git hook:
python -m pip install pre-commit
pre-commit install
Coding style¶
formate is used for code formatting.
It can be run manually via pre-commit
:
pre-commit run formate -a
Or, to run the complete autoformatting suite:
pre-commit run -a
Automated tests¶
Tests are run with tox
and pytest
.
To run tests for a specific Python version, such as Python 3.6:
tox -e py36
To run tests for all Python versions, simply run:
tox
Build documentation locally¶
The documentation is powered by Sphinx. A local copy of the documentation can be built with tox
:
tox -e docs
Downloading source code¶
The domplotlib
source code is available on GitHub,
and can be accessed from the following URL: https://github.com/domdfcoding/domplotlib
If you have git
installed, you can clone the repository with the following command:
git clone https://github.com/domdfcoding/domplotlib
Cloning into 'domplotlib'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 173 (delta 16), reused 17 (delta 6), pack-reused 126
Receiving objects: 100% (173/173), 126.56 KiB | 678.00 KiB/s, done.
Resolving deltas: 100% (66/66), done.

Downloading a ‘zip’ file of the source code¶
Building from source¶
The recommended way to build domplotlib
is to use tox:
tox -e build
The source and wheel distributions will be in the directory dist
.
If you wish, you may also use pep517.build or another PEP 517-compatible build tool.
License¶
domplotlib
is licensed under the MIT License
A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
Permissions | Conditions | Limitations |
---|---|---|
|
|
Copyright (c) 2020 Dominic Davis-Foster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
View the Function Index or browse the Source Code.