/
plot_style.py
116 lines (98 loc) · 4.16 KB
/
plot_style.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#########################
# gs2_correlation #
# Ferdinand van Wyk #
#########################
###############################################################################
# This file is part of gs2_correlation.
#
# gs2_correlation_analysis is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# gs2_correlation is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gs2_correlation.
# If not, see <http://www.gnu.org/licenses/>.
###############################################################################
"""
.. module:: plot_styles
:platform: Unix, OSX
:synopsis: Functions setting plot aesthetics.
.. moduleauthor:: Ferdinand van Wyk <ferdinandvwyk@gmail.com>
"""
# Third Party
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
def white():
"""
Set plot aesthetics for 1D plots with white backgrounds.
The plots are set up to have
* White backgrounds
* Grey minor and major gridlines
* x and y ticks on bottom and left axes
* Thin black outer border
* Minor grid lines halfway between major ticks
"""
pal = sns.color_palette('deep')
sns.set_context('talk')
sns.set_style('whitegrid', {'axes.edgecolor':'0.1',
'legend.frameon': True,
'xtick.color': '.15',
'xtick.major.size': 5,
'xtick.minor.size': 0.0,
'xtick.direction': 'out',
'ytick.color': '.15',
'ytick.major.size': 5,
'ytick.minor.size': 0.0,
'ytick.direction': 'out',
'axes.axisbelow': True,
'axes.linewidth': 0.4,
'font.family': 'sans-serif',
'font.sans-serif': ['Helvetica', 'Arial',
'Verdana', 'sans-serif']
})
def minor_grid(ax):
"""
Sets up a minor grid halfway between major ticks.
This is mainly for 1D whitegrid plots since the gridlines are grey.
"""
ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator( (plt.xticks()[0][1]-plt.xticks()[0][0]) / 2.0 ))
ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator( (plt.yticks()[0][1]-plt.yticks()[0][0]) / 2.0 ))
ax.grid(True, 'major', color='0.92', linestyle='-', linewidth=1.4)
ax.grid(True, 'minor', color='0.92', linestyle='-', linewidth=0.7)
def dark():
"""
Set plot aesthetics for 2D contour plots.
The plots are set up to have
* 'Dark' backgrounds (not usually visible)
* White major gridlines in front of the plot
* x and y ticks on bottom and left axes
* Thin black outer border
"""
sns.set_style('darkgrid', {'axes.edgecolor':'0.1',
'legend.frameon': True,
'xtick.color': '.15',
'xtick.major.size': 5,
'xtick.minor.size': 0.0,
'xtick.direction': 'out',
'ytick.color': '.15',
'ytick.major.size': 5,
'ytick.minor.size': 0.0,
'ytick.direction': 'out',
'axes.axisbelow': False,
'axes.linewidth': 0.4,
'font.family' : 'serif',
})
def ticks_bottom_left(ax):
"""
Sets the ticks to be bottom left only.
"""
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')