-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathplotfunctions.py
80 lines (64 loc) · 2.99 KB
/
plotfunctions.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 27 14:14:07 2019
@author: michaelboles
"""
# import packages
import numpy as np
import matplotlib.pyplot as plt
# plot histogram
def plothist(data, binwidth, textbox, xmin, xmax, xlabel, ylabel, figure_name):
fig, ax = plt.subplots(1,1,figsize=(7,7))
bins = np.arange(round(min(data),1), max(data) + binwidth, binwidth)
props = dict(facecolor='white', alpha=1.0)
ax.hist(data, bins, edgecolor = 'black', facecolor = 'blue')
plt.xlim(xmin, xmax); plt.xlabel(xlabel, fontsize = 18, fontname = 'Helvetica')
plt.ylabel(ylabel, fontsize = 18)
ax.tick_params(axis = 'x', labelsize = 14); ax.tick_params(axis = 'y', labelsize = 14)
ax.text(0.575, 0.97, textbox, transform = ax.transAxes, fontsize = 18, fontname = 'Helvetica', verticalalignment = 'top', bbox = props)
for tick in ax.get_xticklabels():
tick.set_fontname('Helvetica')
for tick in ax.get_yticklabels():
tick.set_fontname('Helvetica')
plt.rcParams['axes.unicode_minus'] = False
plt.grid(); ax.set_axisbelow(True)
plt.savefig(figure_name, dpi = 600)
plt.show()
def plothist2(data1, data2, binwidth, textbox, xmin, xmax, xlabel, ylabel, figure_name):
fig, ax = plt.subplots(1,1,figsize=(7,7))
bins = np.arange(round(min(data1),1), max(data1) + binwidth, binwidth)
props = dict(facecolor='white', alpha=1.0)
ax.hist(data2, bins, edgecolor = 'black', facecolor = 'gray', alpha = 0.5)
ax.hist(data1, bins, edgecolor = 'black', facecolor = 'blue', alpha = 0.5)
plt.xlim(xmin, xmax); plt.xlabel(xlabel, fontsize = 18, fontname = 'Helvetica')
plt.ylabel(ylabel, fontsize = 18)
ax.tick_params(axis = 'x', labelsize = 14); ax.tick_params(axis = 'y', labelsize = 14)
# ax.text(0.575, 0.97, textbox, transform = ax.transAxes, fontsize = 18, fontname = 'Helvetica', verticalalignment = 'top', bbox = props)
for tick in ax.get_xticklabels():
tick.set_fontname('Helvetica')
for tick in ax.get_yticklabels():
tick.set_fontname('Helvetica')
plt.rcParams['axes.unicode_minus'] = False
ax.rcParams['axes.grid'] = False
plt.grid(); ax.set_axisbelow(True)
plt.savefig(figure_name, dpi = 600)
plt.show()
#def plothist2(data, binwidth, xmin, xmax, xlabel, ylabel):
# fig, ax = plt.subplots(1,1,figsize=(7,7))
# bins = np.arange(round(min(data),1), max(data) + binwidth, binwidth)
#
# ax.hist(data, bins, edgecolor = 'black', facecolor = 'blue')
#
# plt.xlim(xmin, xmax); plt.xlabel(xlabel, fontsize = 18, fontname = 'Helvetica')
# plt.ylabel(ylabel, fontsize = 18)
# ax.tick_params(axis = 'x', labelsize = 14); ax.tick_params(axis = 'y', labelsize = 14)
#
# for tick in ax.get_xticklabels():
# tick.set_fontname('Helvetica')
# for tick in ax.get_yticklabels():
# tick.set_fontname('Helvetica')
#
# plt.rcParams['axes.unicode_minus'] = False
# plt.grid(); ax.set_axisbelow(True)
# plt.show()