I'm given a number of data points like this:
2.50% 3.45
25.00% 4.19
50.00% 4.7
75.00% 5.42
97.50% 6.87
This defines a complete box-whisker element for a plot. I'm not sure how I can plot this. All the methods I've looked up so far (MATLAB, matplotlib, gnuplot) construct boxes from the original data. I don't have access to the original data, but I do have all the information I should need to draw the boxes.
What's the best way to draw the boxes/whiskers without the data?
boxplot( x , g ) creates a box plot using one or more grouping variables contained in g . boxplot produces a separate box for each set of x values that share the same g value or values. boxplot( ax ,___) creates a box plot using the axes specified by the axes graphic object ax , using any of the previous syntaxes.
The left and right sides of the box are the lower and upper quartiles. The box covers the interquartile interval, where 50% of the data is found. The vertical line that split the box in two is the median. Sometimes, the mean is also indicated by a dot or a cross on the box plot.
You can use the following trick in Matlab:
Let x
be a vector containing your percentile values:
x = [3.45 4.19 4.7 5.42 6.87];
Let's extend this vector by repeating the median, appending it to the end:
y = [x x((1+end)/2)];
Now the 75, 50 and 25 percentiles of y
, considered as a data vector, coincide with the desired values:
>>prctile(y,75)
ans =
5.4200
>>prctile(y,50)
ans =
4.7000
>>prctile(y,25)
ans =
4.1900
So: simply call boxplot
using this extended vector as data:
boxplot([x x((1+end)/2)])
A nice thing of this approach is that you can use all the fancy options of boxplot
to customize the plot.
The trick can probably be applied to matplotlib and gnuplot as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With