pimpmyplot 0.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.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: pimpmyplot
3
+ Version: 0.0.1
4
+ Summary: Small collection of functions to make better looking matplotlib plots
5
+ Home-page: https://github.com/clarkmaio/pimpmyplot
6
+ Author: andrea maioli
7
+ Author-email: maioliandrea0@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: matplotlib
16
+ Requires-Dist: numpy
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
@@ -0,0 +1,53 @@
1
+
2
+
3
+
4
+ # Pimp My Plot
5
+
6
+ <p align="center">
7
+ <img src="assets/pimpmyplotlogo.png" width="30%"/>
8
+ </p>
9
+
10
+
11
+
12
+ This is a small collection of functions to make better looking matplotlib plots.
13
+
14
+ The package has minimal dependencies and fully compatible with standard `matplotlib` library.
15
+
16
+
17
+
18
+ ## Getting started
19
+
20
+ Install the package via pip
21
+
22
+ ```
23
+ pip instsall pimpmyplot
24
+ ```
25
+
26
+
27
+ Use the package simply calling its functions after you created a matplotlib plot
28
+
29
+
30
+ ```
31
+ import pimpmyplot as pmp
32
+ import matplotlib.pyplot as plt
33
+ import numpy as np
34
+
35
+ x = np.linspace(0, 10, 100)
36
+ plt.figure(figsize=(4, 4))
37
+ plt.plot(x, np.sin(x), label='A')
38
+
39
+ pmp.legend() # same as plt legend but better looking and horizontal labels as default
40
+ pmp.bullet_grid(stepinch=.3) # dotted grid similar to a bllet journal
41
+ pmp.remove_axis('top', 'right') # remove axis in a simpler way
42
+ pmp.remove_ticks() # remove ticks in a simpler way
43
+ ```
44
+
45
+ <br>
46
+ <p align="center">
47
+ <img src="assets/stdplot.png" width="40%"/>
48
+ </p>
49
+
50
+
51
+ ## Demo
52
+
53
+ For a small interactive demo visit [this marimo notebook](https://molab.marimo.io/notebooks/nb_R7uUAUWZfgRioAqmzL9XJm) on molab.
@@ -0,0 +1,8 @@
1
+
2
+
3
+
4
+ from ..setup import __version__
5
+
6
+ from pimpmyplot.axis import *
7
+ from pimpmyplot.legend import *
8
+ from pimpmyplot.grid import bullet_grid
@@ -0,0 +1,43 @@
1
+
2
+
3
+ import matplotlib.pyplot as plt
4
+ import matplotlib
5
+ from typing import List
6
+
7
+ from pimpmyplot.utils import setupax
8
+
9
+
10
+
11
+ @setupax
12
+ def remove_axis(*spines: str, ax: matplotlib.axes.Axes = None) -> None:
13
+ '''
14
+ Make axis not visible.
15
+
16
+ Params
17
+ -------
18
+ *sides : str
19
+ Options: 'top', 'bottom', 'left', 'right'.
20
+ If nothing is passed all axis will be removed
21
+
22
+ ax : plt.axis
23
+ Apply styling to this axis
24
+ '''
25
+
26
+ spines = ['top', 'bottom', 'left', 'right'] if len(spines) == 0 else spines
27
+ for s in spines:
28
+ ax.spines[s].set_visible(False)
29
+
30
+
31
+ def remove_ticks(*spines: str, ax: plt.axis = None) -> None:
32
+
33
+ if not ax:
34
+ ax = plt.gca()
35
+
36
+ spines = ['top', 'bottom', 'left', 'right'] if len(spines) == 0 else spines
37
+ tickkwargs = {s: False for s in spines}
38
+ labelkwargs = {f'label{s}': False for s in spines}
39
+ ax.tick_params(
40
+ **tickkwargs,
41
+ **labelkwargs
42
+ )
43
+
@@ -0,0 +1,47 @@
1
+
2
+
3
+ import matplotlib
4
+ from typing import Dict, Tuple
5
+ import numpy as np
6
+ from pimpmyplot.utils import setupax
7
+
8
+
9
+ _DEFAULT_SCATTER_KWARGS = {
10
+ 's': 2,
11
+ 'color': '#cccccc',
12
+ 'marker': 'o',
13
+ 'alpha': .8,
14
+ 'zorder': -100
15
+ }
16
+
17
+
18
+
19
+ def build_uniform_meshgrid(ax: matplotlib.axes.Axes, stepinch: float = .5) -> Tuple[np.array, np.array]:
20
+ """Create equispaced meshgrid relative to axis scale"""
21
+
22
+ # Deduce axis step to make mesh uniform
23
+ xmin, xmax = ax.get_xlim()
24
+ ymin, ymax = ax.get_ylim()
25
+ xrange, yrange = xmax - xmin, ymax - ymin
26
+ xinch, yinch = ax.figure.get_size_inches()
27
+ axwidth, axheight = ax.get_position().width, ax.get_position().height
28
+ xstep = xrange / (xinch * axwidth) * stepinch
29
+ ystep = yrange / (yinch * axheight) * stepinch
30
+
31
+ xpoints = np.arange(xmin, xmax + xstep/2, xstep)
32
+ ypoints = np.arange(ymin, ymax + ystep/2, ystep)
33
+ X, Y = np.meshgrid(xpoints, ypoints)
34
+ return X, Y
35
+
36
+
37
+
38
+ @setupax
39
+ def bullet_grid(ax: matplotlib.axes.Axes = None, stepinch: float = .5, scatter_kwargs: Dict = {}):
40
+ '''
41
+ Build grid similar to dotted bullet journals
42
+ '''
43
+ X, Y = build_uniform_meshgrid(ax=ax, stepinch=stepinch)
44
+
45
+ scatter_kwargs.update(_DEFAULT_SCATTER_KWARGS)
46
+ ax.scatter(X, Y, **scatter_kwargs)
47
+
@@ -0,0 +1,49 @@
1
+
2
+
3
+ import matplotlib.pyplot as plt
4
+ import matplotlib
5
+
6
+ from pimpmyplot.utils import setupax
7
+
8
+ from typing import Tuple
9
+
10
+
11
+ @setupax
12
+ def legend(*args,
13
+ shadow: bool = True,
14
+ frameon: bool = True,
15
+ loc: str = 'upper center',
16
+ bbox_to_anchor: Tuple = (.5, -.1),
17
+ edgecolor: str = 'k',
18
+ ax: matplotlib.axes.Axes = None,
19
+ ncol: int = None,
20
+ **kwargs) -> matplotlib.legend.Legend:
21
+ '''
22
+ Customize legend
23
+ '''
24
+
25
+ # Deduce number labels in legend
26
+ if ncol is None:
27
+ legend_handles = [line for line in ax.get_lines() if line.get_label() != '_nolegend_']
28
+ ncol = len(legend_handles)
29
+
30
+ # Call standard legend
31
+ l = ax.legend(*args,
32
+ shadow=shadow,
33
+ frameon=frameon,
34
+ loc=loc,
35
+ bbox_to_anchor=bbox_to_anchor,
36
+ edgecolor=edgecolor,
37
+ ncol=ncol,
38
+ **kwargs)
39
+
40
+ # Shadow style
41
+ l._shadow_props = {'ox': 3, 'oy': -3, 'color': 'black', 'shade': 1., 'alpha': 1.}
42
+
43
+ return l
44
+
45
+
46
+
47
+
48
+
49
+
@@ -0,0 +1,19 @@
1
+
2
+
3
+ import matplotlib.pyplot as plt
4
+ from functools import wraps
5
+
6
+
7
+
8
+ def setupax(func):
9
+ '''
10
+ If func takes in input ax argument replace it with plt.gca() in case it is None
11
+ '''
12
+ @wraps(func)
13
+ def wrapper(*args, **kwargs):
14
+ if 'ax' in kwargs:
15
+ kwargs['ax'] = plt.gca() if not kwargs['ax'] else kwargs['ax']
16
+ else:
17
+ kwargs['ax'] = plt.gca()
18
+ return func(*args, **kwargs)
19
+ return wrapper
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: pimpmyplot
3
+ Version: 0.0.1
4
+ Summary: Small collection of functions to make better looking matplotlib plots
5
+ Home-page: https://github.com/clarkmaio/pimpmyplot
6
+ Author: andrea maioli
7
+ Author-email: maioliandrea0@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
13
+ Requires-Python: >=3.7
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: matplotlib
16
+ Requires-Dist: numpy
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
@@ -0,0 +1,13 @@
1
+ README.md
2
+ setup.py
3
+ pimpmyplot/__init__.py
4
+ pimpmyplot/axis.py
5
+ pimpmyplot/grid.py
6
+ pimpmyplot/legend.py
7
+ pimpmyplot/utils.py
8
+ pimpmyplot.egg-info/PKG-INFO
9
+ pimpmyplot.egg-info/SOURCES.txt
10
+ pimpmyplot.egg-info/dependency_links.txt
11
+ pimpmyplot.egg-info/requires.txt
12
+ pimpmyplot.egg-info/top_level.txt
13
+ test/test_functions.py
@@ -0,0 +1,2 @@
1
+ matplotlib
2
+ numpy
@@ -0,0 +1 @@
1
+ pimpmyplot
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,30 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ __version__ = '0.0.1'
4
+
5
+ with open('README.md', 'r', encoding='utf-8') as f:
6
+ long_description = f.read()
7
+
8
+ setup(
9
+ name='pimpmyplot',
10
+ version=__version__,
11
+ author='andrea maioli',
12
+ author_email='maioliandrea0@gmail.com',
13
+ description='Small collection of functions to make better looking matplotlib plots',
14
+ #long_description=long_description,
15
+ long_description_content_type='text/markdown',
16
+ url='https://github.com/clarkmaio/pimpmyplot',
17
+ packages=find_packages(),
18
+ classifiers=[
19
+ 'Programming Language :: Python :: 3',
20
+ 'License :: OSI Approved :: MIT License',
21
+ 'Operating System :: OS Independent',
22
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
23
+ 'Topic :: Scientific/Engineering :: Mathematics',
24
+ ],
25
+ python_requires='>=3.7',
26
+ install_requires=[
27
+ "matplotlib",
28
+ "numpy"
29
+ ],
30
+ )
@@ -0,0 +1,57 @@
1
+
2
+
3
+
4
+
5
+ import matplotlib.pyplot as plt
6
+ import numpy as np
7
+ import pimpmyplot as pmp
8
+
9
+
10
+ def demoplot():
11
+ x = np.linspace(0, 10, 100)
12
+ plt.plot(x, np.sin(x), label='A')
13
+
14
+ def demosubplot():
15
+ x = np.linspace(0, 10, 100)
16
+ fig, ax = plt.subplots(1, 2)
17
+
18
+ ax[0].plot(x, np.sin(x), label='A')
19
+ ax[1].plot(x, np.cos(x), label='B')
20
+ return fig, ax
21
+
22
+
23
+
24
+
25
+ def test_remove_axis():
26
+ demoplot()
27
+ pmp.remove_axis()
28
+
29
+ fig, ax = demosubplot()
30
+ pmp.remove_axis(ax=ax[1])
31
+
32
+
33
+ def test_remove_ticks():
34
+ demoplot()
35
+ pmp.remove_ticks()
36
+
37
+ fig, ax = demosubplot()
38
+ pmp.remove_ticks(ax=ax[1])
39
+
40
+
41
+ def test_legend():
42
+ demoplot()
43
+ pmp.legend()
44
+
45
+ fig, ax = demosubplot()
46
+ pmp.legend(ax=ax[1])
47
+
48
+
49
+ def test_bullet_grid():
50
+ demoplot()
51
+ pmp.bullet_grid()
52
+
53
+ fig, ax = demosubplot()
54
+ pmp.bullet_grid(ax=ax[1])
55
+
56
+
57
+