-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmplfuncs.py
More file actions
80 lines (55 loc) · 2.07 KB
/
mplfuncs.py
File metadata and controls
80 lines (55 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# pylint: disable=C0103, too-few-public-methods, locally-disabled, no-self-use, unused-argument
'''helper funcs for matplotlib'''
from enum import Enum as _Enum
import pandas as _pd
INCH = 2.54
class FigWidthsCM(_Enum):
minimal = 3
single_col = 9
one_and_a_half_col = 14
two_col = 19
class FigWidthsInch(_Enum):
minimal = 1.181
two_thirds_col = 2.362
single_col = 3.543
one_and_a_half_col = 5.512
two_col = 7.480
def yaxis_hideticklabels(ax):
'''hide tick labels'''
labels = [item.get_text() for item in ax.get_yticklabels()]
empty_string_labels = ['']*len(labels)
ax.set_yticklabels(empty_string_labels)
def xaxis_hideticklabels(ax):
'''hide tick labels'''
labels = [item.get_text() for item in ax.get_xticklabels()]
empty_string_labels = ['']*len(labels)
ax.set_xticklabels(empty_string_labels)
def yaxis_hidelabel(ax):
ax.yaxis.label.set_visible(False)
def xaxis_hidelabel(ax):
ax.xaxis.label.set_visible(False)
def label_pts(x, y, lbls, ax):
'''(list|ndarray, list|ndarray, list|ndarray, matplotlib.Axes)->None
Label points
'''
a = _pd.concat({'x': x, 'y': y, 'val': lbls}, axis=1)
for i, point in a.iterrows():
ax.text(point['x'], point['y'], str(point['val']))
def legend_remove(ax):
'''remove legend'''
ax.legend_.remove()
def xaxis_scale(ax, x1, x2):
'''set xaxis scale'''
ax.set_xlim(x1, x2)
def yaxis_scale(ax, y1, y2):
'''set yaxis scale'''
ax.set_ylim(y1, y2)
def legend_pos(ax, pos, x=None, y=None):
raise NotImplementedError('See https://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot')
#Example of hiding the legend, then adding in with custom labels, this will get rid of the title as well
#g = sns.lineplot(x='Angle', y='MV adjusted error %', hue='CNN', style='CNN', data=df, legend=False)
#g.legend(g.lines, ('nas', 'res', 'ssd'), bbox_to_anchor=(0,1.02,1,0.2), loc="center left", mode="expand", borderaxespad=0, ncol=3, title='')
def cm2inch1(v):
'''(int|float)->int|float
'''
return v / INCH