matplotlib的boxplot上画横线

 1 import matplotlib.pyplot as plt
 2 import numpy as np
 3 
 4 # Generate some data...
 5 data = np.random.random((100, 1))
 6 # y = data.mean(axis=0)
 7 # x = np.random.random(y.size) * 10
 8 # x -= x.min()
 9 # x.sort()
10 
11 # Plot a line between the means of each dataset
12 # plt.plot(x, y, 'b-')
13 
14 # Save the default tick positions, so we can reset them...
15 # locs, labels = plt.xticks() 
16 
17 # boxplot
18 plt.boxplot(data)#, positions=x, notch=True)
19 
20 # horizontal line plot
21 axes = plt.gca()
22 left, right = axes.get_xlim()
23 axes.hlines(y=0.5, xmin=left, xmax=right, linestyles='dashed')
24 
25 # Reset the xtick locations.
26 # plt.xticks(locs)
27 plt.show()
原文地址:https://www.cnblogs.com/andy-0212/p/10062242.html