-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathplot_error.py
More file actions
70 lines (53 loc) · 1.94 KB
/
plot_error.py
File metadata and controls
70 lines (53 loc) · 1.94 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
"""
Example for a Matplotlib plot with the following features:
- Error bar plot
- Error fill plot
"""
__author__ = "Thomas Guillod"
__copyright__ = "Thomas Guillod - Dartmouth College"
__license__ = "Mozilla Public License Version 2.0"
import os
import numpy as np
import matplotlib.pyplot as plt
import utils_mpl
# ###########################################################
# Plot global parameters and define dummy data
# ###########################################################
# set global parameters
utils_mpl.set_global()
# create the output folder
os.makedirs("render", exist_ok=True)
# define dummy data
x = np.linspace(0, 2, 11)
y = 2 + 2 * x**2
e = 0.1 + 0.1 * y
# get the axis ticks
xticks = np.linspace(0.0, 2.0, 4)
yticks = np.linspace(2.0, 11.0, 5)
# ###########################################################
# Definition of the line plot
# ###########################################################
# create a figure with a determined size
(fig, ax) = utils_mpl.get_fig(size=(3.5, 3.0), dpi=200)
# add the plot curves
ax.fill_between(x, y - e, y + e, color="g", alpha=0.2, edgecolors=None)
ax.errorbar(x, y, yerr=e, lw=1.5, marker="o", ms=3.0, capsize=3.0, ecolor="r", color="g")
# set the x-axis limit and format
utils_mpl.set_x_axis(ax, bnd=xticks, margin=0.05, log=False)
utils_mpl.set_format(ax.xaxis, ticks=xticks, fmt="${x:.2f}$")
# set the y-axis limit and format
utils_mpl.set_y_axis(ax, bnd=yticks, margin=0.05, log=False)
utils_mpl.set_format(ax.yaxis, ticks=yticks, fmt="${x:.2f}$")
# set the legend and labels
ax.set_xlabel("x-axis (unit)")
ax.set_ylabel("y-axis (unit)")
ax.set_title("Plot Title")
# set the grid
utils_mpl.set_grid(fig, ax, major=True, minor=False)
# save the plot for Inkscape
utils_mpl.save_svg(fig, "render/error.svg")
# ###########################################################
# Show the plots
# ###########################################################
# show the plot for inspection
plt.show()