|
@@ -1,5 +1,6 @@
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
+import matplotlib
|
|
|
import matplotlib as mpl
|
|
|
import matplotlib.pyplot as plt
|
|
|
from cycler import cycler
|
|
@@ -39,8 +40,8 @@ def pre_paper_plot(change=True):
|
|
|
plt.rcParams['axes.labelsize'] = 14
|
|
|
plt.rcParams['axes.titlesize'] = 14
|
|
|
plt.rcParams['legend.fontsize'] = 10
|
|
|
- plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
|
|
|
- plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
|
|
|
+ plt.rcParams['xtick.labelsize'] = 12
|
|
|
+ plt.rcParams['ytick.labelsize'] = 12
|
|
|
plt.rcParams['savefig.dpi'] = 300
|
|
|
plt.rcParams['xtick.major.size'] = 3
|
|
|
plt.rcParams['xtick.minor.size'] = 3
|
|
@@ -56,7 +57,7 @@ def pre_paper_plot(change=True):
|
|
|
plt.rcParams['axes.linewidth'] = 1
|
|
|
plt.rcParams['legend.handlelength'] = 3
|
|
|
|
|
|
-def post_paper_plot(change=True, bw_friendly=False, adjust_spines=False):
|
|
|
+def post_paper_plot(change=True, bw_friendly=False, adjust_spines=False, sci_y=False):
|
|
|
if not change:
|
|
|
return
|
|
|
if adjust_spines:
|
|
@@ -66,6 +67,12 @@ def post_paper_plot(change=True, bw_friendly=False, adjust_spines=False):
|
|
|
plt.gca().yaxis.set_ticks_position('left')
|
|
|
if bw_friendly:
|
|
|
setFigLinesBW(plt.gcf())
|
|
|
+ setBarsBW(plt.gcf())
|
|
|
+ if sci_y:
|
|
|
+ # Change the Y axis to use a scientific notation and render it with LaTeX.
|
|
|
+ formatter = matplotlib.ticker.ScalarFormatter(useMathText=True)
|
|
|
+ formatter.set_powerlimits((-2,2))
|
|
|
+ plt.gca().yaxis.set_major_formatter(formatter)
|
|
|
|
|
|
# Following functions taken from:
|
|
|
# https://stackoverflow.com/questions/7358118/matplotlib-black-white-colormap-with-dashes-dots-etc
|
|
@@ -75,15 +82,15 @@ def setAxLinesBW(ax):
|
|
|
Take each Line2D in the axes, ax, and convert the line style to be
|
|
|
suitable for black and white viewing.
|
|
|
"""
|
|
|
- marker_size = 5
|
|
|
+ marker_size = 4
|
|
|
|
|
|
color_map = {
|
|
|
'#1f77b4': {'marker': None, 'dash': (None,None)},
|
|
|
- '#ff7f0e': {'marker': None, 'dash': [3,4]},
|
|
|
- '#2ca02c': {'marker': None, 'dash': [5,3,2,1]},
|
|
|
- '#d62728': {'marker': None, 'dash': [1,3]},
|
|
|
- '#9467bd': {'marker': None, 'dash': [5,2,5,2,5,10]},
|
|
|
- '#8c564b': {'marker': None, 'dash': [5,3,1,2,1,10]},
|
|
|
+ '#ff7f0e': {'marker': None, 'dash': [2,1]},
|
|
|
+ '#2ca02c': {'marker': None, 'dash': [3,1,1,1]},
|
|
|
+ '#d62728': {'marker': None, 'dash': [3,1,1,1,1,1]},
|
|
|
+ '#9467bd': {'marker': None, 'dash': [1,1]},
|
|
|
+ '#8c564b': {'marker': None, 'dash': [4,1,2,0.5,0.3,0.5]},
|
|
|
'#e377c2': {'marker': 'o', 'dash': (None,None)} #[1,2,1,10]}
|
|
|
}
|
|
|
|
|
@@ -97,9 +104,12 @@ def setAxLinesBW(ax):
|
|
|
for line in lines_to_adjust:
|
|
|
orig_color = line.get_color()
|
|
|
#line.set_color('black')
|
|
|
- line.set_dashes(color_map[orig_color]['dash'])
|
|
|
- line.set_marker(color_map[orig_color]['marker'])
|
|
|
- line.set_markersize(marker_size)
|
|
|
+ try :
|
|
|
+ line.set_dashes(color_map[orig_color]['dash'])
|
|
|
+ line.set_marker(color_map[orig_color]['marker'])
|
|
|
+ line.set_markersize(marker_size)
|
|
|
+ except KeyError:
|
|
|
+ print('Warning: could not add patterns to custom color "{}"'.format(orig_color))
|
|
|
|
|
|
def setFigLinesBW(fig):
|
|
|
"""
|
|
@@ -108,3 +118,13 @@ def setFigLinesBW(fig):
|
|
|
"""
|
|
|
for ax in fig.get_axes():
|
|
|
setAxLinesBW(ax)
|
|
|
+
|
|
|
+def setBarsBW(fig):
|
|
|
+ patterns = ['0', '///', '---', '|||', '+++', '**', 'oo', '...']
|
|
|
+ inx = 0
|
|
|
+ for ax in fig.get_axes():
|
|
|
+ for child in ax.get_children():
|
|
|
+ if isinstance(child, matplotlib.patches.Rectangle):
|
|
|
+ child.set_hatch(patterns[inx])
|
|
|
+ inx += 1
|
|
|
+ if inx == len(patterns): inx = 0
|