Advertisement
Isaacmm

Gabi

Mar 31st, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. import sys
  2. import csv
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import matplotlib.lines as mlines
  6.  
  7.  
  8. def csv_to_list(file):
  9.     with open(file, 'r') as f:
  10.         reader = csv.reader(f)
  11.         data = list(map(float, list(reader)[0]))
  12.         return data
  13.  
  14.  
  15. def main(argv):
  16.     boxplot_data = []
  17.     for arg in argv:
  18.         boxplot_data.append(csv_to_list(arg))
  19.  
  20.     temperature = [0.0, 30.0, 50.0, 100.0]
  21.     fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(30, 30))
  22.     box = plt.boxplot(boxplot_data, vert=False, patch_artist=True, widths=0.35)
  23.  
  24.     plt.rcParams.update({'font.size': 16, 'axes.titleweight': 'bold'})
  25.  
  26.     colors = ['orange', 'magenta', 'yellowgreen']
  27.     for patch, color in zip(box['boxes'], colors):
  28.         patch.set_facecolor(color)
  29.  
  30.     ax.yaxis.grid(True)
  31.     ax.set_title('Zależność wielkości cząstek od temperatury')
  32.     ax.set_xlabel('Wielkość [nm]')
  33.     ax.set_ylabel('Temperatura [°C]')
  34.  
  35.     plt.xlim([0.00, 4.3])
  36.     plt.xticks(np.arange(0, 4.3, 0.1))
  37.     plt.boxplot(boxplot_data, 0, 'rD', 0, 0.6)
  38.     plt.yticks(np.arange(4), temperature)
  39.  
  40.     for label in ([ax.xaxis.label, ax.yaxis.label]):
  41.         label.set_fontsize(16)
  42.  
  43.     for label in (ax.get_xticklabels() + ax.get_yticklabels()):
  44.         label.set_fontsize(10)
  45.  
  46.     lines = []
  47.     for i, color in enumerate(colors):
  48.         lines.append(mlines.Line2D([], [], color=color, marker='_',
  49.                                    markersize=8, label=f'próbki nr {i+1}'))
  50.     plt.legend(handles=lines, loc='lower right')
  51.     plt.grid(True)
  52.     plt.show()
  53.  
  54.  
  55. if __name__ == '__main__':
  56.     main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement