-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_3vars_savefig.py
More file actions
69 lines (41 loc) · 1.39 KB
/
Copy pathplot_3vars_savefig.py
File metadata and controls
69 lines (41 loc) · 1.39 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
"""
E. Wes Bethel, Copyright (C) 2022
October 2022
Description: This code loads a .csv file and creates a 3-variable plot, and saves it to a file named "myplot.png"
Inputs: the named file "sample_data_3vars.csv"
Outputs: displays a chart with matplotlib
Dependencies: matplotlib, pandas modules
Assumptions: developed and tested using Python version 3.8.8 on macOS 11.6
"""
import pandas as pd
import matplotlib.pyplot as plt
plot_fname = "myplot.png"
fname = "sample_data_3vars.csv"
df = pd.read_csv(fname, comment="#")
print(df)
var_names = list(df.columns)
print("var names =", var_names)
# split the df into individual vars
# assumption: column order - 0=problem size, 1=blas time, 2=basic time
problem_sizes = df[var_names[0]].values.tolist()
code1_time = df[var_names[1]].values.tolist()
code2_time = df[var_names[2]].values.tolist()
code3_time = df[var_names[3]].values.tolist()
plt.figure()
plt.title("Comparison of 3 Codes")
xlocs = [i for i in range(len(problem_sizes))]
plt.xticks(xlocs, problem_sizes)
plt.plot(code1_time, "r-o")
plt.plot(code2_time, "b-x")
plt.plot(code3_time, "g-^")
#plt.xscale("log")
#plt.yscale("log")
plt.xlabel("Problem Sizes")
plt.ylabel("runtime")
varNames = [var_names[1], var_names[2], var_names[3]]
plt.legend(varNames, loc="best")
plt.grid(axis='both')
# save the figure before trying to show the plot
plt.savefig(plot_fname, dpi=300)
plt.show()
# EOF