-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrq2.py
74 lines (58 loc) · 2.8 KB
/
rq2.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
#
# This is the code for plotting the figures for RQ1. It is optimized towards plotting exactly those figures
# Use data_analysis.py for explorative data analysis
#
import matplotlib
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
from plotting_utils import load_data_from_folder, create_custom_palette, \
filter_data_and_plot_as_boxplots, filter_data_by_tag, store_figure_to_paper_folder
import matplotlib.pyplot as plt
def preprare_the_figure(plot_data):
fontsize = 20
min_fontsize = 16
color_palette = create_custom_palette()
# Create the figure
fig = plt.figure(figsize=(16, 10))
# Set the figure to be a grid with 1 column and 2 rows without space between them
gs = fig.add_gridspec(2, hspace=0)
# Get the axes objects
axs = gs.subplots(sharex=True)
# Plot the top plot
axs[0] = filter_data_and_plot_as_boxplots(axs[0], "Filled Cells", plot_data, color_palette)
# Plot the bottom plot
axs[1] = filter_data_and_plot_as_boxplots(axs[1], "Coverage Sparseness", plot_data, color_palette)
# Adjust the plots
# Put a legend to the right of the current axis
axs[0].legend(bbox_to_anchor=(1.04,1), loc="upper left",borderaxespad=0,fontsize=fontsize)
# Increase font for y-label and y-ticks
axs[0].set_ylabel(axs[0].get_ylabel(), fontsize=fontsize)
axs[0].tick_params(axis='y', which='major', labelsize=min_fontsize)
# Remove the legend from the bottom plot
axs[1].legend([], [], frameon=False)
# Remove the x - label
axs[1].set_xlabel('')
# Increase only the size of x-ticks, but split the combinations in two lines
# https://stackoverflow.com/questions/11244514/modify-tick-label-text
axs[1].set_xticklabels([l.get_text().replace("-", "\n") for l in axs[1].get_xticklabels()], fontsize=fontsize)
# Increase label y-label and y-ticks
axs[1].set_ylabel("Cov. Sparseness", fontsize=fontsize)
axs[1].tick_params(axis='y', which='major', labelsize=min_fontsize)
# Align the y labels: -0.1 moves it a bit to the left, 0.5 move it in the middle of y-axis
axs[0].get_yaxis().set_label_coords(-0.08, 0.5)
axs[1].get_yaxis().set_label_coords(-0.08, 0.5)
return fig
def main():
# Load all the data and select the required feature combinations
mnist_data = load_data_from_folder("./data/mnist")
mnist_data = filter_data_by_tag(mnist_data, ["rescaled"])
mnist_figure = preprare_the_figure(mnist_data)
# # Store
store_figure_to_paper_folder(mnist_figure, file_name="RQ2-MNIST")
beamng_data = load_data_from_folder("./data/beamng")
beamng_data = filter_data_by_tag(beamng_data, ["rescaled"])
beamng_figure = preprare_the_figure(beamng_data)
# Store
store_figure_to_paper_folder(beamng_figure, file_name="RQ2-BeamNG")
if __name__ == "__main__":
main()