gpt4 book ai didi

python - 如何在 OpenTurns Viewer 上设置轴限制?

转载 作者:行者123 更新时间:2023-12-04 09:13:36 24 4
gpt4 key购买 nike

我正在使用 openturns 来找到最适合我的数据的分布。我必须绘制它,但 X 限制比我想要的要大得多。我的代码是:

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)
我想将 X 限制设置为“graph.setXLim”之类的东西,就像我们在 matplotlib 中所做的那样,但由于我是 OpenTurns 的新手,所以我一直坚持使用它。
提前致谢。

最佳答案

任何 OpenTURNS 图都有一个 getBoundingBox将边界框作为维度 2 返回的方法 Interval .我们可以使用 getLowerBound 来获取/设置这个区间的下限和上限。和 getUpperBound .这些边界中的每一个都是 Point维度为 2。因此,我们可以在使用 View 之前设置图形的边界。类(class)。
在以下示例中,我创建了一个包含高斯分布 PDF 的简单图形。

import openturns as ot
import openturns.viewer as otv
n = ot.Normal()
graph = n.drawPDF()
_ = otv.View(graph)
Bell curve
假设我想将下 X 轴设置为 -1。
剧本:
boundingBox = graph.getBoundingBox()
lb = boundingBox.getLowerBound()
print(lb)
产生:
[-4.10428,-0.0195499]
Point 中的第一个值是 X 下限,第二个是 Y 下限。以下脚本将下限的第一个分量设置为 -1,将下限包装到边界框并将边界框设置到图形中。
lb[0] = -1.0
boundingBox.setLowerBound(lb)
graph.setBoundingBox(boundingBox)
_ = otv.View(graph)
这会产生下图。
Bell curve with minimum X axis equal to -1
这些方法的优点是它们在由 Matplotlib 完成渲染之前从库中配置图形。缺点是它们比 Matplotlib 对应物更冗长。

关于python - 如何在 OpenTurns Viewer 上设置轴限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63309636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com