This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/plotting/code/scaling.py

53 lines
1.9 KiB
Python

import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as spst
y_data = np.arange(89., 99., 1.) + np.random.randn(10) * 3.;
x_labels = ['10.18', '11.18', '12.18', '01.19', '02.19',
'03.19', '04.19','05.19','06.19','07.19']
x_data = np.arange(len(x_labels))
slope, intercept, _, _, _ = spst.linregress(x_data, y_data)
fit = x_data * slope + intercept
fig = plt.figure()
fig.set_size_inches(7.5, 2.5)
ax1 = plt.subplot2grid((2, 5), (0, 0), rowspan=2)
ax2 = plt.subplot2grid((2, 5), (0, 1), rowspan=2)
ax3 = plt.subplot2grid((2, 5), (1, 2), rowspan=1)
ax4 = plt.subplot2grid((2, 5), (0, 3), rowspan=2, colspan=2)
ax1.grid(axis='y', zorder=0)
ax1.scatter(x_data, y_data, zorder=3)
ax1.plot(x_data, fit, zorder=4, color='r')
ax1.set_ylim([85, 101])
ax1.set_xticks(x_data[0::2])
ax1.set_xticklabels(x_labels[0::2], rotation=45, fontsize=9)
ax1.text(-0.3, 1.05, "A", transform=ax1.transAxes, size=12)
ax2.grid(axis='y', zorder=0)
ax2.scatter(x_data, y_data, zorder=3)
ax2.plot(x_data, fit, zorder=4, color='r')
ax2.set_ylim([0, 120])
ax2.set_xticks(x_data[0::2])
ax2.set_xticklabels(x_labels[0::2], rotation=45, fontsize=9)
ax2.text(-0.3, 1.05, "B", transform=ax2.transAxes, size=12)
ax3.grid(axis='y', zorder=0)
ax3.scatter(x_data, y_data, zorder=3)
ax3.plot(x_data, fit, zorder=4, color='r')
ax3.set_ylim([85, 101])
ax3.set_xticks(x_data[0::2])
ax3.set_xticklabels(x_labels[0::2], rotation=45, fontsize=9)
ax3.text(-0.3, 1.1, "C", transform=ax3.transAxes, size=12)
ax4.grid(axis='y', zorder=0)
ax4.scatter(x_data, y_data, zorder=3)
ax4.plot(x_data, fit, zorder=4, color='r')
ax4.set_ylim([85, 101])
ax4.set_xticks(x_data)
ax4.set_xticklabels(x_labels, rotation=45, fontsize=9)
ax4.text(-0.15, 1.05, "D", transform=ax4.transAxes, size=12)
fig.subplots_adjust(left=0.05, top=0.9, bottom=0.175, right=0.97, hspace=0.5, wspace=0.4)
plt.savefig('../lecture/images/plot_scaling.pdf')