I'm using openturns to find the best fit distribution for my data. I got to plot it alright, but the X limit is far bigger than I'd like. My code is:
import statsmodels.api as sm
import openturns as ot
import openturns.viewer as otv
data = in_seconds
sample = ot.Sample(data, 1)
tested_factories = ot.DistributionFactory.GetContinuousUniVariateFactories()
best_model, best_bic = ot.FittingTest.BestModelBIC(sample, tested_factories)
print(best_model)
graph = ot.HistogramFactory().build(sample).drawPDF()
bestPDF = best_model.drawPDF()
bestPDF.setColors(["blue"])
graph.add(bestPDF)
name = best_model.getImplementation().getClassName()
graph.setLegends(["Histogram",name])
graph.setXTitle("LatĂȘncias (segundos)")
graph.setYTitle("FrequĂȘncia")
otv.View(graph)
I'd like to set X limits as something like "graph.setXLim", as we'd do in matplotlib, but I'm stuck with it as I'm new to OpenTurns.
Thanks in advance.
Any OpenTURNS graph has a
getBoundingBoxmethod which returns the bounding box as a dimension 2Interval. We can get/set the lower and upper bounds of this interval withgetLowerBoundandgetUpperBound. Each of these bounds is aPointwith dimension 2. Hence, we can set the bounds of the graphics prior to the use of theViewclass.In the following example, I create a simple graph containing the PDF of the gaussian distribution.
Suppose that I want to set the lower X axis to -1. The script:
produces:
The first value in the
Pointis the X lower bound and the second is the Y lower bound. The following script sets the first component of the lower bound to -1, wraps the lower bound into the bounding box and sets the bounding box into the graph.This produces the following graph.
The advantage of these methods is that they configure the graphics from the library, before the rendering is done by Matplotlib. The drawback is that they are a little more verbose than the Matplotlib counterpart.