diff --git a/plot.png b/plot.png new file mode 100644 index 0000000..ff015d0 Binary files /dev/null and b/plot.png differ diff --git a/plot.py b/plot.py new file mode 100644 index 0000000..a57d875 --- /dev/null +++ b/plot.py @@ -0,0 +1,52 @@ +import numpy as np +import matplotlib.pyplot as plt +import pandas as pd + +# load the data +colnames = ["year", "#students", "beer"] +data = pd.read_csv( + "istherecorrelation.csv", + delimiter=";", + names=colnames, + skiprows=1, +) + +# reformat the data to be compatible for plotting +data["beer"] = data["beer"].astype(float) +for i in range(len(data["#students"])): + data.loc[i, "#students"] = data.loc[i, "#students"].replace(",", ".") + data.loc[i, "beer"] = data.loc[i, "beer"] * 10 ** (-4) +data["#students"] = data["#students"].astype(float) + + +# plot the data +fig, ax1 = plt.subplots(1, figsize=(8, 4), dpi=300) +ax2 = ax1.twinx() +axes = [ax1, ax2] +colors = ["darkred", "coral"] +ylabels = [r"$N_{students}~[\cdot 10^3]$", r"beer consumed [$\cdot 10^9$ L]"] +width = 0.25 # width of the bins +range_ratio = 0 +for i in range(2): + ax = axes[i] + plotdata = np.array(data[colnames[i + 1]]).astype(float) + ax.bar( + x=data["year"].values + width * i, + height=plotdata, + width=width * 0.8, + color=colors[i], + ) + if np.max(plotdata) / np.min(plotdata) > range_ratio: + range_ratio = np.max(plotdata) / np.min(plotdata) + # ax.set_ylim(np.min(plotdata) * 0.9, np.max(plotdata) * 1.05) + ax.tick_params(axis="y", labelcolor=colors[i]) + ax.set_ylabel(ylabels[i], color=colors[i]) +ax1.set_ylim( + np.min(data["#students"]) * 0.95, np.min(data["#students"]) * range_ratio * 1.05 +) +ax2.set_ylim(np.min(data["beer"]) * 0.95, np.min(data["beer"]) * range_ratio * 1.05) +ax1.set_xlim(np.min(data["year"]) - 0.5, np.max(data["year"]) + 0.5 + width) +ax1.set_xticks(data["year"] + width / 2, data["year"]) +plt.tight_layout() +plt.savefig("plot.png") +plt.show() diff --git a/solution_.md b/solution_.md new file mode 100644 index 0000000..066d88a --- /dev/null +++ b/solution_.md @@ -0,0 +1,9 @@ +
Student number: 13274864
+Paper 1: Fantastic yeasts and where to find them: the hidden diversity of dimorphic fungal pathogens
+Paper 2: An analysis of the forces required to drag sheep over various surfaces
+Paper 3: The neurocognitive effects of alcohol on adolescents and college students
As can be seen from the plot above, both the amount of students and annual beer consumption have been increasing in the period of 2006 to 2018. However, the relative increase of students is far higher than the relative increase in beer consumptions, such that we can conclude that, on average, students consume less beer throughout the years. Note that, although the range limits on the y-axis are not the same, the relative range sizes are the same.