3

I need to plot a series of boxplots, based on results of numerical air quality model. Since this is a significant amount of data, I trigger calculation of aggregates (min, max, quartiles, etc.) every time when new model results become ready and store them in PostgreSQL. For visualization purpose I load the aggregates into pandas and I plot them using dash. I am able to plot line plots of timeseries, however I would like to get something like this example, but also interactive.

As I went through plotly examples, it looks like it always require the raw data for ploting boxplots ( https://plot.ly/python/box-plots/#basic-box-plot ). I really enjoy the concept of presentation and logic separation. Is it possible to get a plotly box plot based on aggregated data?

2

1 Answer 1

5

You can provide your aggreate values to a Plotly boxplot in Python by providing it in the following format:

plotly.graph_objs.Box(y=[val_min, 
                         val_lower_box, 
                         val_lower_box, 
                         val_median, 
                         val_upper_box, 
                         val_upper_box, 
                         val_max])

e.g.

import plotly
plotly.offline.init_notebook_mode()

val_min = 1
val_lower_box = 2
val_median = 3
val_upper_box = 4.5
val_max = 6

box_plot = plotly.graph_objs.Box(y=[val_min, 
                                    val_lower_box, 
                                    val_lower_box, 
                                    val_median, 
                                    val_upper_box, 
                                    val_upper_box, 
                                    val_max])
plotly.offline.iplot([box_plot])

gives you

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Maximillian. That's a smart walkaround.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.