maxplotlibx 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. maxplotlibx-0.1/LICENSE +21 -0
  2. maxplotlibx-0.1/PKG-INFO +64 -0
  3. maxplotlibx-0.1/README.md +29 -0
  4. maxplotlibx-0.1/pyproject.toml +49 -0
  5. maxplotlibx-0.1/setup.cfg +4 -0
  6. maxplotlibx-0.1/src/maxplotlib/__init__.py +3 -0
  7. maxplotlibx-0.1/src/maxplotlib/backends/matplotlib/utils.py +136 -0
  8. maxplotlibx-0.1/src/maxplotlib/backends/matplotlib/utils_old.py +852 -0
  9. maxplotlibx-0.1/src/maxplotlib/backends/plotly/__init__.py +0 -0
  10. maxplotlibx-0.1/src/maxplotlib/backends/plotly/utils.py +0 -0
  11. maxplotlibx-0.1/src/maxplotlib/canvas/__init__.py +0 -0
  12. maxplotlibx-0.1/src/maxplotlib/canvas/canvas.py +526 -0
  13. maxplotlibx-0.1/src/maxplotlib/colors/__init__.py +0 -0
  14. maxplotlibx-0.1/src/maxplotlib/colors/colors.py +85 -0
  15. maxplotlibx-0.1/src/maxplotlib/linestyle/__init__.py +0 -0
  16. maxplotlibx-0.1/src/maxplotlib/linestyle/linestyle.py +58 -0
  17. maxplotlibx-0.1/src/maxplotlib/objects/__init__.py +0 -0
  18. maxplotlibx-0.1/src/maxplotlib/objects/layer.py +20 -0
  19. maxplotlibx-0.1/src/maxplotlib/objects/node.py +0 -0
  20. maxplotlibx-0.1/src/maxplotlib/objects/path.py +0 -0
  21. maxplotlibx-0.1/src/maxplotlib/subfigure/__init__.py +0 -0
  22. maxplotlibx-0.1/src/maxplotlib/subfigure/line_plot.py +357 -0
  23. maxplotlibx-0.1/src/maxplotlib/subfigure/subfigure.py +3 -0
  24. maxplotlibx-0.1/src/maxplotlib/subfigure/tikz_figure.py +497 -0
  25. maxplotlibx-0.1/src/maxplotlib/tests/test_canvas.py +7 -0
  26. maxplotlibx-0.1/src/maxplotlib/tests/test_imports.py +12 -0
  27. maxplotlibx-0.1/src/maxplotlib/tests/test_plot.py +0 -0
  28. maxplotlibx-0.1/src/maxplotlibx.egg-info/PKG-INFO +64 -0
  29. maxplotlibx-0.1/src/maxplotlibx.egg-info/SOURCES.txt +30 -0
  30. maxplotlibx-0.1/src/maxplotlibx.egg-info/dependency_links.txt +1 -0
  31. maxplotlibx-0.1/src/maxplotlibx.egg-info/requires.txt +25 -0
  32. maxplotlibx-0.1/src/maxplotlibx.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Max
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: maxplotlibx
3
+ Version: 0.1
4
+ Summary: A reproducible plotting module with various backends and export options.
5
+ Author: Max
6
+ Project-URL: Source, https://github.com/max-models/maxplotlib
7
+ Keywords: matplotlib
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: matplotlib
13
+ Requires-Dist: pint
14
+ Requires-Dist: plotly
15
+ Provides-Extra: test
16
+ Requires-Dist: pytest; extra == "test"
17
+ Requires-Dist: coverage; extra == "test"
18
+ Provides-Extra: docs
19
+ Requires-Dist: myst-parser; extra == "docs"
20
+ Requires-Dist: sphinx; extra == "docs"
21
+ Requires-Dist: sphinx-rtd-theme; extra == "docs"
22
+ Requires-Dist: nbsphinx; extra == "docs"
23
+ Requires-Dist: ipykernel; extra == "docs"
24
+ Requires-Dist: nbconvert; extra == "docs"
25
+ Provides-Extra: dev
26
+ Requires-Dist: maxplotlibx[docs,test]; extra == "dev"
27
+ Requires-Dist: ruff; extra == "dev"
28
+ Requires-Dist: black; extra == "dev"
29
+ Requires-Dist: isort; extra == "dev"
30
+ Requires-Dist: jupyterlab; extra == "dev"
31
+ Requires-Dist: nbstripout; extra == "dev"
32
+ Requires-Dist: pre-commit; extra == "dev"
33
+ Requires-Dist: pyproject-fmt; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # maxplotlib
37
+
38
+ This is a wrapper for matplotlib so I can produce figures with consistent formatting. It also has some pretty nice additions such as using layers and exporting to tikz.
39
+
40
+ Related packages: [maxtikzlib](https://github.com/max-models/maxtikzlib) and [maxtexlib](https://github.com/max-models/maxtexlib).
41
+
42
+ ## Install
43
+
44
+ Create and activate python environment
45
+
46
+ ```
47
+ python -m venv env
48
+ source env/bin/activate
49
+ pip install --upgrade pip
50
+ ```
51
+
52
+ Install the code and requirements with pip
53
+
54
+ ```
55
+ pip install -e .
56
+ ```
57
+
58
+ Additional dependencies for developers can be installed with
59
+
60
+ ```
61
+ pip install -e ".[dev]"
62
+ ```
63
+
64
+ Some examples can be found in `tutorials/`
@@ -0,0 +1,29 @@
1
+ # maxplotlib
2
+
3
+ This is a wrapper for matplotlib so I can produce figures with consistent formatting. It also has some pretty nice additions such as using layers and exporting to tikz.
4
+
5
+ Related packages: [maxtikzlib](https://github.com/max-models/maxtikzlib) and [maxtexlib](https://github.com/max-models/maxtexlib).
6
+
7
+ ## Install
8
+
9
+ Create and activate python environment
10
+
11
+ ```
12
+ python -m venv env
13
+ source env/bin/activate
14
+ pip install --upgrade pip
15
+ ```
16
+
17
+ Install the code and requirements with pip
18
+
19
+ ```
20
+ pip install -e .
21
+ ```
22
+
23
+ Additional dependencies for developers can be installed with
24
+
25
+ ```
26
+ pip install -e ".[dev]"
27
+ ```
28
+
29
+ Some examples can be found in `tutorials/`
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "maxplotlibx"
7
+ version = "0.1"
8
+ description = "A reproducible plotting module with various backends and export options."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {file = "LICENSE.txt"}
12
+ keywords = ["matplotlib"]
13
+ authors = [{name = "Max"}]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ ]
17
+ dependencies = [
18
+ "matplotlib",
19
+ "pint",
20
+ "plotly",
21
+ ]
22
+ [project.optional-dependencies]
23
+ test = [
24
+ "pytest",
25
+ "coverage",
26
+ ]
27
+ docs = [
28
+ "myst-parser",
29
+ "sphinx",
30
+ "sphinx-rtd-theme",
31
+ "nbsphinx",
32
+ "ipykernel",
33
+ "nbconvert",
34
+ ]
35
+ dev = [
36
+ "maxplotlibx[test,docs]",
37
+ "ruff",
38
+ "black",
39
+ "isort",
40
+ "jupyterlab",
41
+ "nbstripout",
42
+ "pre-commit",
43
+ "pyproject-fmt",
44
+ ]
45
+ [project.urls]
46
+ "Source" = "https://github.com/max-models/maxplotlib"
47
+
48
+ [tool.setuptools.packages.find]
49
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from maxplotlib.canvas.canvas import Canvas
2
+
3
+ __all__ = ["Canvas"]
@@ -0,0 +1,136 @@
1
+ # import sys; from os.path import dirname; sys.path.append(f'{dirname(__file__)}/../../')
2
+
3
+ # import matplotlib.pylab as pylab
4
+ import math
5
+ import pickle
6
+ from pathlib import Path
7
+
8
+ import _pickle as cPickle
9
+ import matplotlib.colors as mcolors
10
+ import matplotlib.pyplot as plt
11
+ import numpy as np
12
+ import pint
13
+ from matplotlib.collections import PatchCollection
14
+ from mpl_toolkits.mplot3d import Axes3D
15
+ from mpl_toolkits.mplot3d.art3d import Line3DCollection, Poly3DCollection
16
+
17
+
18
+ def setup_tex_fonts(fontsize=14, usetex=False):
19
+ """
20
+ Sets up LaTeX fonts for plotting.
21
+ """
22
+ tex_fonts = {
23
+ "text.usetex": usetex,
24
+ "font.family": "serif",
25
+ "pgf.rcfonts": False,
26
+ "axes.labelsize": fontsize,
27
+ "font.size": fontsize,
28
+ "legend.fontsize": fontsize,
29
+ "xtick.labelsize": fontsize,
30
+ "ytick.labelsize": fontsize,
31
+ }
32
+ plt.rcParams.update(tex_fonts)
33
+ return tex_fonts
34
+
35
+
36
+ def setup_plotstyle(
37
+ tex_fonts=None,
38
+ axes_grid=False,
39
+ axes_grid_which="major",
40
+ grid_alpha=1.0,
41
+ grid_linestyle="dotted",
42
+ ):
43
+ """
44
+ Configures the plot style.
45
+ """
46
+ if tex_fonts:
47
+ plt.rcParams.update(tex_fonts)
48
+ plt.rcParams["axes.grid"] = axes_grid
49
+ plt.rcParams["axes.grid.which"] = axes_grid_which
50
+ plt.rcParams["grid.alpha"] = grid_alpha
51
+ plt.rcParams["grid.linestyle"] = grid_linestyle
52
+ plt.rcParams["xtick.direction"] = "in"
53
+ plt.rcParams["ytick.direction"] = "in"
54
+ plt.rcParams["xtick.major.pad"] = 8
55
+ plt.rcParams["ytick.major.pad"] = 8
56
+
57
+
58
+ # TODO: Use the other unit package
59
+ # Create a UnitRegistry
60
+ ureg = pint.UnitRegistry()
61
+
62
+
63
+ def convert_to_inches(length_str):
64
+ quantity = ureg(length_str) # Parse the input string
65
+ return quantity.to("inch").magnitude # Convert to inches
66
+
67
+
68
+ def _2pt(width, dpi=300):
69
+ if isinstance(width, (int, float)):
70
+ return width
71
+ elif isinstance(width, str):
72
+ length_in = convert_to_inches(width)
73
+ length_pt = length_in * dpi
74
+ # print(f"{length_in = } {length_pt = }")
75
+ return length_pt
76
+ else:
77
+ raise NotImplementedError
78
+
79
+
80
+ def set_size(width, fraction=1, ratio="golden", dpi=300):
81
+ """
82
+ Sets figure dimensions to avoid scaling in LaTeX.
83
+ """
84
+ if width == "thesis":
85
+ width_pt = 426.79135
86
+ elif width == "beamer":
87
+ width_pt = 307.28987
88
+ else:
89
+ width_pt = _2pt(width=width, dpi=dpi)
90
+
91
+ fig_width_pt = width_pt * fraction
92
+ # inches_per_pt = 1 / 72.27
93
+
94
+ # Calculate the figure height based on the desired ratio
95
+ if ratio == "golden":
96
+ golden_ratio = (5**0.5 - 1) / 2
97
+ fig_height_pt = fig_width_pt * golden_ratio
98
+ elif ratio == "square":
99
+ fig_height_pt = fig_width_pt
100
+ elif isinstance(ratio, (int, float)):
101
+ fig_height_pt = fig_width_pt * ratio
102
+ else:
103
+ raise ValueError("Invalid ratio specified.")
104
+ fig_dim = (fig_width_pt, fig_height_pt)
105
+ return fig_dim
106
+
107
+
108
+ def create_lineplot(
109
+ nx_subplots=1,
110
+ ny_subplots=1,
111
+ width=426.79135,
112
+ figsize=None,
113
+ dpi=300,
114
+ ratio="golden",
115
+ gridspec_kw=None,
116
+ ):
117
+ """
118
+ Creates a line plot figure and axes.
119
+ """
120
+ if figsize is not None:
121
+ fig_width, fig_height = figsize
122
+ else:
123
+ fig_width, fig_height = set_size(width, ratio=ratio)
124
+
125
+ if gridspec_kw is None:
126
+ gridspec_kw = {"wspace": 0.08, "hspace": 0.1}
127
+
128
+ fig, axs = plt.subplots(
129
+ ny_subplots,
130
+ nx_subplots,
131
+ figsize=(fig_width, fig_height),
132
+ dpi=dpi,
133
+ constrained_layout=False,
134
+ gridspec_kw=gridspec_kw,
135
+ )
136
+ return fig, axs