Ploting box plot from statistical summary data

2019-08-26 07:33发布

问题:

I would like to add a box plot to my page. Something like this (using Plotly.js).

The problem with implementing the example from the link above is that the plotly.js library expect all the points, whereas I only have access to the already computed statistical data. In other words, I would like to plot the graphic by passing max, min, med, avr, stdev (statistical data of the series) instead of all the data points themselves.

P.s.: Using plotly.js is not a requirement. I could go with D3.js only if that is an option.

回答1:

You can provide the values for the box plot in the y-value of the Plotly box plot object. See the snippet below and the discussion here.

var min = 1;
var max = 11;
var med = 4.25;
var stdev = 2;

var y = [min,
         med - stdev,
         med - stdev,
         med,
         med + stdev,
         med + stdev,
         max
        ];

var box = {
  y: y,
  type: 'box'
};

Plotly.newPlot('myDiv', [box]);
<head>
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
        
<body>
  <div id="myDiv"></div>
</body>