I used matplotlib to create a histogram. There are still problems I couldn't solve on my own or with the help of the internet.
How can I change the color of certain bins? In detail I want to change the color of bins with: a.) value bin < 1.15 red, b.) value 1.15 < bin < 1.25 c.) value > 1.25 red?
How can I label the X-Axis not only with numbers with 1 decimal but also with 2 decimals (right now simply not plotted)?
import matplotlib.pyplot as plt import numpy as np import csv thickness = [] #gets thickness from list bins = [1.00,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.10,1.11,1.12,1.13,1.14,1.15,1.16,1.17,1.18,1.19,1.20,1.21,1.22,1.23,1.24,1.25,1.26,1.27,1.28,1.29,1.30,1.31,1.32,1.33,1.34,1.35,1.36,1.37,1.38,1.39,1.40,1.41,1.42,1.43,1.44,1.45,1.46,1.47,1.48,1.49,1.50 ] #set bins manuelly with open('control.txt','r') as csvfile: plots = csv.reader(csvfile, delimiter=',') for row in plots: #x.append(float(row[0])) thickness.append(float(row[1])) plt.hist(thickness, bins, align='left', histtype='bar', rwidth=0.8, color='green') plt.xlabel('thickness [mm]') plt.ylabel('frequency') plt.title('Histogram') plt.show()
See the plotted histogram below: