Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plt.boxplot(data, vert = False) - adding one data point per boxplot - python 2.7, Matplotlib 1.5.3

Have been trying to add one single point to my boxplots. I would like just to add a point as the black ones in the image below.

data_2 = [pd.read_csv(data).values for data in os.listdir(wd)]
bp = plt.boxplot(data_2, labels = labels, vert = False, showfliers = False)
plt.show()

Any ideas for how I should go with that? You can click here to see the pic

enter image description here

like image 740
pedropedro Avatar asked Jun 10 '26 16:06

pedropedro


1 Answers

You can just plot individual points after the boxplot is finished, just give the appropiate coordinates:

import numpy as np
import matplotlib.pyplot as plt

data = np.array( [
np.random.normal( 0.19, 0.1, 100 ),
np.random.normal( 0.17, 0.1, 100 ),
np.random.normal( 0.11, 0.1, 100 ),
np.random.normal( 0.16, 0.1, 100 ),
np.random.normal( 0.15, 0.1, 100 ) ] ).T

labels = [ 'pred2012', 'pred2007', 'pred2002', 'pred1995', 'pred1988' ]

fig, ax = plt.subplots()
ax.boxplot( data, labels=labels, vert = False, showfliers = False)
ax.plot( -0.1, 4, marker='o' ) 
ax.plot( 0.3, 3, marker='*', markersize=20 ) 
plt.savefig( 'boxplot.png' )
plt.show()

enter image description here

like image 61
Luis Avatar answered Jun 16 '26 07:06

Luis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!