如何使用matplotlib将x移到无穷大时绘制f(x)? [英] How to plot f(x) as x goes to infinity with matplotlib?

查看:58
本文介绍了如何使用matplotlib将x移到无穷大时绘制f(x)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一些数据点绘制一条曲线:

I'm plotting a curve from some data points:

points = [[0.0, 0.0], [1, 3], [3, 5]]

...,我希望它随着x变为 infinity 达到y = 10.换句话说,要追加的额外点"将是:[float('inf'), 10]

... and I want it to reach, say, y = 10 as x goes to infinity. In other words, the extra "point" to append would be: [float('inf'), 10]

有没有办法告诉 matplotlib 绘制曲线最后一部分的渐近行为?

Is there a way to tell matplotlib to plot the asymptotic behaviour of this last part of the curve?

Matplotlib忽略了 float('info'),所以我想应该有另一种方法.

Matplotlib disregards float('info'), so I guess there should be another way to do this.

推荐答案

您无法绘制无穷大的函数,因为它不是数字.我认为实现您想要的效果的唯一方法是使用断轴并将数据点绘制为任意大的数字.可以从matplotlib官方网站上获得有关如何执行散点图的示例.

You can't plot a function of infinity because it isn't a number. I think the only way to achieve the effect that you want is with a broken axis and the data point plotted at some arbitrarily large number. An example of how to do the broken plot is available from the official matplotlib site.

基本思想是创建两个子图,并巧妙地去除边界,使其看起来像一个单一的图,然后添加一些花哨的对角线,使其看起来像一个传统的破碎"图.您可以通过替换足够大的数字(使曲线看起来正确)在其自己的子图中绘制无穷大数据点.然后只需将刻度重新标记为无穷大 (ax.set_xticks([large_number]) ax.set_xticklabels(['\infty']) 假设 ax是第二个只有无穷大点的情节)并且你在做生意!

The basic idea is to create two subplots with borders cleverly removed so as to look like a single plot then add some fancy diagonal lines to make it look like a conventional "broken" plot. You can plot your infinity data point in its own subplot by substituting a sufficiently large number (to make the curve look right). Then just relabel the tick to infinity (ax.set_xticks([large_number]) ax.set_xticklabels(['\infty']) assuming ax is the second plot that only has your infinity point) and you're in business!

我最近使用了上面示例的修改形式来绘制无穷大"点.我有执行此操作的代码,但它充满了对我的特定数据的引用,因此它可能与官方示例一样对您有帮助.

I have recently used a modified form of the above example to plot a point "at infinity". I have code that does this but it's full of references to my specific data so it will probably be about as helpful to you as the official example.

这篇关于如何使用matplotlib将x移到无穷大时绘制f(x)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆