For my thesis I have to do a boxplot. There are 4 series indicating the different techniques (D16, D50, D84, D96). Each of those series has 12 boxplots named L 1 - L 12. Now I would like to replace the locations (L1-L12) with the distance values. The X scale needs to be log10 from 1 till 100. The Y Achse in a normal even scale between o and 45 cm.
import numpy as np
import matplotlib.pyplot as plt
import os
directory = os.getcwd()
D16_Boot_M = []
D50_Boot_M = []
D84_Boot_M = []
D96_Boot_M = []
count = 1
folders_number = 13
while count < folders_number:
Temp_D16_Boot = np.loadtxt(directory + f"/S{count}M/D16_Bootstrapping_Array.txt")
D16_Boot_M.extend(Temp_D16_Boot)
Temp_D50_Boot = np.loadtxt(directory + f"/S{count}M/D50_Bootstrapping_Array.txt")
D50_Boot_M.extend(Temp_D50_Boot)
Temp_D84_Boot = np.loadtxt(directory + f"/S{count}M/D84_Bootstrapping_Array.txt")
D84_Boot_M.extend(Temp_D84_Boot)
Temp_D96_Boot = np.loadtxt(directory + f"/S{count}M/D96_Bootstrapping_Array.txt")
D96_Boot_M.extend(Temp_D96_Boot)
count += 1
distance = (2.6, 3.2, 4, 4.5, 5, 5.8, 7.4, 15.1, 54.6, 60, 70, 80)
my_dict = {'L 1': D16_Boot_M[0], 'L 2': D16_Boot_M[1], 'L 3': D16_Boot_M[2], 'L 4': D16_Boot_M[3], 'L 5': D16_Boot_M[4], 'L 6': D16_Boot_M[5], 'L 7': D16_Boot_M[6],
'L 8': D16_Boot_M[7], 'L 9': D16_Boot_M[8], 'L 10': D16_Boot_M[9], 'L 11': D16_Boot_M[10], 'L 12': D16_Boot_M[11]}
fig, ax = plt.subplots()
bplot = ax.boxplot(my_dict.values(), showfliers=False, patch_artist=True, medianprops=dict(color="black",linewidth=0.3), whiskerprops = dict(linewidth=0.3), boxprops= dict(linewidth=0.3), capprops=dict(linewidth=0.3), widths=0.15)
colors = ['lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue']
for patch, color in zip(bplot['boxes'], colors):
patch.set_facecolor('r')
# D50 Ls BoxPlot
my_dict2 = {'L 1': D50_Boot_M[0], 'L 2': D50_Boot_M[1], 'L 3': D50_Boot_M[2], 'L 4': D50_Boot_M[3], 'L 5': D50_Boot_M[4], 'L 6': D50_Boot_M[5], 'L 7': D50_Boot_M[6],
'L 8': D50_Boot_M[7], 'L 9': D50_Boot_M[8], 'L 10': D50_Boot_M[9], 'L 11': D50_Boot_M[10], 'L 12': D50_Boot_M[11]}
bplot2 = ax.boxplot(my_dict2.values(), showfliers=False, patch_artist=True, medianprops=dict(color="black",linewidth=0.3), whiskerprops = dict(linewidth=0.3), boxprops= dict(linewidth=0.3), capprops=dict(linewidth=0.3), widths=0.15)
colors = ['lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue']
for patch, color in zip(bplot2['boxes'], colors):
patch.set_facecolor('m')
# D84 Ls BoxPlot
my_dict3 = {'L 1': D84_Boot_M[0], 'L 2': D84_Boot_M[1], 'L 3': D84_Boot_M[2], 'L 4': D84_Boot_M[3], 'L 5': D84_Boot_M[4], 'L 6': D84_Boot_M[5], 'L 7': D84_Boot_M[6],
'L 8': D84_Boot_M[7], 'L 9': D84_Boot_M[8], 'L 10': D84_Boot_M[9], 'L 11': D84_Boot_M[10], 'L 12': D84_Boot_M[11]}
bplot3 = ax.boxplot(my_dict3.values(), showfliers=False, patch_artist=True, medianprops=dict(color="black",linewidth=0.3), whiskerprops = dict(linewidth=0.3), boxprops= dict(linewidth=0.3), capprops=dict(linewidth=0.3), widths=0.15)
colors = ['lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue']
for patch, color in zip(bplot3['boxes'], colors):
patch.set_facecolor('b')
# D96 Ls BoxPlot
my_dict4 = {'L 1': D96_Boot_M[0], 'L 2': D96_Boot_M[1], 'L 3': D96_Boot_M[2], 'L 4': D96_Boot_M[3], 'L 5': D96_Boot_M[4], 'L 6': D96_Boot_M[5], 'L 7': D96_Boot_M[6],
'L 8': D96_Boot_M[7], 'L 9': D96_Boot_M[8], 'L 10': D96_Boot_M[9], 'L 11': D96_Boot_M[10], 'L 12': D96_Boot_M[11]}
bplot4 = ax.boxplot(my_dict4.values(), showfliers=False, patch_artist=True, medianprops=dict(color="black",linewidth=0.3), whiskerprops = dict(linewidth=0.3), boxprops= dict(linewidth=0.3), capprops=dict(linewidth=0.3), widths=0.15)
colors = ['lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue','lightblue', 'lightblue']
for patch, color in zip(bplot4['boxes'], colors):
patch.set_facecolor('y')
ax.set_title("Grain Size Percentiles - Wolman")
ax.set_ylabel("Grain size in cm")
ax.set_xlabel("Sampling Locations")
ax.grid(alpha=0.5)
ax.legend([bplot4["boxes"][0], bplot3["boxes"][0], bplot2["boxes"][0], bplot["boxes"][0]], ['D96', 'D84','D50', 'D16'], loc='upper right')
plt.xticks([1, 2, 3,4,5,6,7,8,9,10,11,12], ['L 1', 'L 2', 'L 3', 'L 4', 'L 5', 'L 6', 'L 7', 'L 8', 'L 9', 'L 10', 'L 11', 'L 12'])
plt.axis([0.5, 12.5, 0, 45])
plt.tight_layout()
plt.savefig("Boxplot_Overview.png", dpi=500)
Every solution I tried so far failed to give a file, or made a blank page ...