Matplotlib连续行到无穷大 [英] Matplotlib continuing line into infinity

查看:90
本文介绍了Matplotlib连续行到无穷大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图形,它是由.txt文件中的数据制成的.目前,Matplotlib会将其图形化到我文件的最后一点.我需要它来继续下去.我似乎记得某处说过我可以让一条线延续到无穷大.(我并不是指使用微积分和限制时的无穷大,我只是指屏幕上的直线,直到图形的边缘.)

I have a graph, made from data in .txt files. Currently, Matplotlib will graph it to the last point in my file. I need it to continue farther that that. I seem to remember something somewhere saying that I could make a line continue into infinity. (I don't mean infinity when using calculus and limits, I just mean a line going of the screen, until the edge of the graph.)

现在,我知道如果我有曲线图,这将是不准确的,因为这条线将永远以最后一个数据点的角度继续延伸.但是,由于我有一个直线图,所以这是理想的.

Now, I know this would not be accurate if I had a curved graph, because the line would continue forever at the angle out of the last datapoint. However, since I have a straight-line graph, this would be ideal.

有谁知道这是否可能,如果可能,如何?我已经做过研究,但不记得我在哪里看到的文档条目说我可以做到这一点,所以如果有人能对此有所了解,我将不胜感激.

Does anyone know if this is possible and if so, how? I have done research, and cannot remember where I saw the doc entry saying I could do this, so if someone could shed light on this I'd really appreciate it.

推荐答案

从一个小到很黑,这确实很黑,但是您可以问matplotlib这个图的当前边界是什么

On a scale from one to hacky, this is pretty hacky, but you can ask matplotlib what the current bounds of the plot are

import matplotlib.pyplot as plt

plt.plot([0,10], [0,10])
plt.axis()

返回:

(0.0, 10.0, 0.0, 10.0)

这太笨重了,但是您可以找出最后两点的直线方程,然后找出该直线与边界框相交的位置.然后从最后一点到BB画一条线.

This is super clunky, but you could figure out the equation of the line of the last two points, and then figure out where that line intersects the bounding box. Then plot a line from the last point to the BB.

新想法,不那么笨重.延长最后两点的线,然后将轴设置回原来的位置.

New idea, slightly less clunky. Extend the line of the last two points, then set the axes back to what they were.

import numpy
import matplotlib.pyplot as plt

X = [0, 1, 2]
Y = [4, 6, 4]

plt.plot(X,Y)
axes = plt.axis()
plt.plot([X[-2],X[-2]+1000*(X[-1]-X[-2])], [Y[-2],Y[-2]+1000*(Y[-1]-Y[-2])])
plt.xlim( [axes[0], axes[1]])
plt.ylim( [axes[2], axes[3]])
plt.show()

这篇关于Matplotlib连续行到无穷大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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