# -*- coding: utf-8 -*- """ Created on Sat Mar 7 10:41:51 2020 @author: Johan Rene van Dorp """ import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.read_csv('OldFaithFul.csv') Durations = df["Duration (s)"] WaitingTimes = df["Waiting Time (Min)"] # Plotting Boxplot with two panels plt.rc('font', family='serif', size='10') plt.figure(figsize=(10, 5)) BoxPlot_Figure = plt.figure() BoxPlot_Figure.set_figwidth(9) BoxPlot_Figure.set_figheight(4.5) BoxPlot_Figure.subplots_adjust(hspace=0.4, wspace=0.4) # Plotting the left panel box plot Left_Panel = BoxPlot_Figure.add_subplot(1,2,1) box_LP=plt.boxplot(Durations,notch='True',patch_artist=True) plt.ylabel('Data',size='12') # changing the fill color of the box plot colors = ['LightSalmon'] for patch, color in zip(box_LP['boxes'], colors): patch.set_facecolor(color) # changing color and linewidth of # medians for median in box_LP['medians']: median.set(color ='red', linewidth = 2) # Adding Jitter to the Boxplot y = Durations jitter = np.random.normal(0.75, 0.04, size=len(y)) for x, val, c in zip(box_LP, y, colors): plt.scatter(jitter, y, alpha=0.4, color='gray',s=5) # Setting the x-axis labels Left_Panel.set_xticklabels(['Duration (in Sec)'],size='12') # Plotting the right panel box plot Right_Panel = BoxPlot_Figure.add_subplot(1,2,2) box_RP=plt.boxplot(WaitingTimes,notch='True',patch_artist=True) plt.ylabel('Data',size='12') # changing the fill color of the box plot colors = ['LightBlue'] for patch, color in zip(box_RP['boxes'], colors): patch.set_facecolor(color) # changing color and linewidth of # medians for median in box_RP['medians']: median.set(color ='red', linewidth = 2) # Adding Jitter to the Boxplot y = WaitingTimes jitter = np.random.normal(0.75, 0.04, size=len(y)) for x, val, c in zip(box_LP, y, colors): plt.scatter(jitter, y, alpha=0.4, color='gray',s=5) # Setting the x-axis labels Right_Panel.set_xticklabels(['Waiting Times (in Min)'],size='12') BoxPlot_Figure.suptitle('Boxplot of Durations (s) and Waiting Times (min)',size='14') plt.savefig('Old_Faithful_Box.png', dpi=300)