-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphs_template.py
109 lines (85 loc) · 3.12 KB
/
Graphs_template.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
#-----------------------------------------------------#
# GRAPH PLOTS TEMPLATE #
# © Jona Cappelle #
# (based on michiel's latex params) #
#-----------------------------------------------------#
# pip install pandas matplotlib
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import math
from matplotlib.ticker import ScalarFormatter
#-----------------------------------------------------#
# SETTINGS #
#-----------------------------------------------------#
# Esthetical ratio
golden_mean = (math.sqrt(5)-1.0)/2.0
# Adjust to your liking
width = 5 #inches
height = width * golden_mean #inches
fontsize = 11 #pt
axis_linewidth = 0.4 #pt
# Params LaTeX
mpl.use("pgf")
mpl.rcParams.update({
'backend': 'ps',
'axes.labelsize': fontsize,
'axes.titlesize': fontsize,
'legend.fontsize': fontsize,
'xtick.labelsize': fontsize,
'ytick.labelsize': fontsize,
'axes.linewidth' : axis_linewidth,
'text.usetex': True,
"pgf.rcfonts": False,
"pgf.texsystem": "lualatex",
'font.family': 'serif',
"pgf.preamble": [
r"\usepackage[utf8x]{inputenc}", # use utf8 fonts
r"\usepackage[T1]{fontenc}", # plots will be generated
r"\usepackage[detect-all]{siunitx}" # to use si units
]
})
#-----------------------------------------------------#
# READ DATA #
#-----------------------------------------------------#
data = pd.read_csv('path_to_file.csv')
data.head()
# Give name to data columns, will be used below
data.columns = ['x', 'y']
#-----------------------------------------------------#
# PLOTTING #
#-----------------------------------------------------#
# Figure size
# plt.figure(1,figsize=(width,height))
fig, ax = plt.subplots(figsize=(width,height))
# Black & white option
# plt.style.use('grayscale')
# Plot grid onder data + lichter grid
plt.rc('axes', axisbelow=True)
ax.grid(color='silver', linestyle='-', linewidth=0.25, alpha=0.5)
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Point plot
# plt.scatter(data['x'], data['y'], s=5, color='grey') # s=5 --> size of points
# Line plot
ax.plot(data['x'], data['y'], c='0.4') # c=0.4 --> nice grey!
# Select range
# plt.xlim(lower,upper)
# plt.ylim(lower,upper)
# Log scale
# plt.yscale('log')
# plt.xscale('log')
# No legend
# ax.legend().remove()
# Set labels
plt.ylabel("ylabel")
plt.xlabel("xlabel")
#-----------------------------------------------------#
# SAVE FILE #
#-----------------------------------------------------#
plt.savefig('filename.pgf', bbox_inches='tight')
# OPTIONS
# tweede plot met plt.figure(2, figsize=(width, height))
# Plot done!
print("Done!")