简体   繁体   English

通过两点画线,而不是在两点之间画线(在对数刻度上,但仍然是一条直线)

[英]Drawing line through two points, instead of between (on a log scale, but still a straight line)

I am currently working on a Python API responsible for plotting diagrams and tangents made in a Front-end application using Angular.我目前正在开发一个 Python API,负责绘制在使用 Angular 的前端应用程序中制作的图表和切线。 In this application it is possible to move points to adjust the a line perpendicular to the curve.在此应用程序中,可以移动点来调整垂直于曲线的直线。

When the user thinks this is the way it is supposed to be the diagrams can be exported using matplotlib.当用户认为这是应该的方式时,可以使用 matplotlib 导出图表。

When only drawing between points using code below:当仅使用以下代码在点之间绘制时:

x_values = [tangent.point1.x, tangent.point2.x]
y_values = [tangent.point1.y, tangent.point2.y]
plt.plot(x_values, y_values, scalex=False, scaley=False)

I get normal looking lines as follows我得到正常的线条如下在此处输入图像描述

Although I want the lines to keep going till the borders of the plot for if the two points set by the user do not intersect by themselves.尽管我希望线条一直延伸到绘图的边界,因为如果用户设置的两个点本身不相交。

I have tried converting the two points into an equation, and calculate two points from there but without luck (straight line).我试过将这两个点转换成一个方程,并从那里计算出两个点但没有运气(直线)。 Also tried using np.linspace(xMin, xMax, 100) resulting on a exponential curve.还尝试使用 np.linspace(xMin, xMax, 100) 产生指数曲线。

If curious, this is what the user would interact with如果好奇,这就是用户会与之交互的内容在此处输入图像描述

Question / TLDR: Is there a way to draw the line through the points (indefinetely because I set scalex and scaley to false in the plt.plot)问题/TLDR:有没有办法通过点画线(不确定因为我在 plt.plot 中将 scalex 和 scaley 设置为 false)

EDIT:编辑:

I have come across in another post ax.axline(p1, p2).我在另一篇文章中遇到过 ax.axline(p1, p2)。 This draws an infinite line but does not have a scalex and scaley attribute.这绘制了一条无限线,但没有 scalex 和 scaley 属性。 This post also referenced storing plt.axes() in a variable and applying them as xlim and ylim after plotting.这篇文章还提到了将 plt.axes() 存储在变量中并在绘图后将它们应用为 xlim 和 ylim。 This results in the lines not being visible???这导致线条不可见??? I mean printing the points to the console.我的意思是将这些点打印到控制台。 I can see where the line is supposed to be in the diagram, it is just not there.我可以看到这条线应该在图中的什么位置,只是不在那里。

EDIT 2: I am stoopid and p1 in axline was p1.x and p2.x instead of p1.x and p1.y.编辑 2:我很愚蠢,axline 中的 p1 是 p1.x 和 p2.x 而不是 p1.x 和 p1.y。 This solved by not going out of bounds and being visible again.这通过不越界并再次可见来解决。

To draw infinite lines one can use one of the following (maybe other options aswell)要绘制无限线,可以使用以下方法之一(也可以使用其他选项)

plt.axlines((x1,y1), (x2,y2))

ax.axlines((x1, y1),(x2, y2))

Having both of the points within the bounding will extend the line to the edges of the bounding box.将两个点都放在边界内会将线延伸到边界框的边缘。

If the points were to be outside of the bounding box, the bounding box will scale accordingly to fit the specified points within the box如果点在边界框之外,边界框将相应地缩放以适应框中的指定点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM