pimpmyplot 0.0.1__py3-none-any.whl

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.
pimpmyplot/__init__.py ADDED
@@ -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
pimpmyplot/axis.py ADDED
@@ -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
+
pimpmyplot/grid.py ADDED
@@ -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
+
pimpmyplot/legend.py ADDED
@@ -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
+
pimpmyplot/utils.py ADDED
@@ -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,9 @@
1
+ pimpmyplot/__init__.py,sha256=zIqAg83Jfucd-EtdwnkFWTSlOKMjOSSlXeGl6_yVi38,138
2
+ pimpmyplot/axis.py,sha256=MetK59lc0jlp2-VnhYslKWZnre8WCu1iLpv2e1r82d4,941
3
+ pimpmyplot/grid.py,sha256=lYlTcFXoo7NU-1rdNF7AacBLfnHmDJtyKICAiKHE_fs,1268
4
+ pimpmyplot/legend.py,sha256=doj61slAgF1xIvK0H-5GzC1pezI4-o3h3_VNQbZGV5c,1107
5
+ pimpmyplot/utils.py,sha256=DD-d3D7IwV3VYflkmrbtU2MPfrcUTxHtM5xqq7gT1ps,444
6
+ pimpmyplot-0.0.1.dist-info/METADATA,sha256=1vbAYTsqqvtXE1lh9efaUyUaJo7wjhQkwQ8TxjmE4HA,806
7
+ pimpmyplot-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ pimpmyplot-0.0.1.dist-info/top_level.txt,sha256=4w6jM0kymzs9nn38Jw2V-hAI1bQ0vRADWi0xRYPCgiE,11
9
+ pimpmyplot-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ pimpmyplot