I have a 3D plot with a surface z = f(x,y) and a level curve g(x,y) = c. This last one lies in the xy-plane. I need to somehow mark out the points on the surface which lie directly above the level curve. I am trying to maximize f, but are restricted to the points directly above g(x,y)=c. Therefore, for illustrational purposes, it would be nice to make it clear for my readers which points we are evaluating. My current plot looks like this:
Current plot
My first idea was to somehow collect the points on g(x,y) = c, adding them to a list, and then again plot z = f(x,y) with these points as the argument. Is that overcomplicating things?
I know that Python has commands for projecting from surfaces to the xy-plane. What I am trying here is kinda the other way around. Does Python have a command for that?
Answers are highly appreciated.
Related
I am currently working on a Python API responsible for plotting diagrams and tangents made in a Front-end application using 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.
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.
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)
EDIT:
I have come across in another post ax.axline(p1, p2). This draws an infinite line but does not have a scalex and scaley attribute. This post also referenced storing plt.axes() in a variable and applying them as xlim and ylim after plotting. 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. 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
I was asked to make an animation using python, and I was thinking to animate an object making a circular path in uniform motion, but it would be really great if the plane of the circular motion also changes constantly over time (like those oversimplified atom animations), so I tried to figure some parametric equation using spherical coordinates, but I landed on differential equations something that I was supposed to learn next year. Does anyone know how to parameterize this kind of motion?
For the orientation of the plane, you could use latitude and longitude of the normal vector, with a third parameter to describe the angle along the circular path. In order to get cartesian coordinates you will need to figure out the transformation (x, y, z) = f(latitude, longitude, rotation). There are no differential equations involved, just a lot of sin() and cos().
I am a chemist, so programming isn't my daily work. However for one project, I am building a little programm on NMR product operators.
I have an vector with quiver, which always has its one point in [0,0,0] and just the head of the arrow is moveable, e.g. from the z to the y axis ([0,0,1] to [0,1,0]).
Right now I just can plot first the one vector and then the other. Is it possible to let the arrow rotate from one position to the other?
I would like to draw the trayectories of an industrial robot plotting lines in 3D. I have already something in mind but I am stuck because I want to plot points relative to different frames. I tried something but it is not very elegant. Sorry for not showing it here the source code, technical problems.
I will use matplotlib and Python to program it.
Question: Is there a function in matplotlib to draw relative points in 3D space?
Relative to what?
It is YOU who can best tell the coordinates of the point.
If you want to count everything relative to a p0(x0,y0) point, then you add the x0, y0 values to each point.
from matplotlib import pyplot as pl
points = [[2,2],[3,3],[4,4],[5,5]]
p0 = [3,3]
for p in points:
pl.plot(p[0]+p0[0], p[1]+p0[1], "r.")
print p[0]+p0[0], p[1]+p0[1]
pl.show()
If you use numpy then you can even add the p0 to a whole array storing the coordinates.
If you want to calculate each point relative to the previous one, then do so, just little change in the code.
So I have been creating mesh's using software called BlueKenue for hydraulic models, which is great. In the document I am currently writing I would like to include an image of the mesh however the mesh's I have constructed are very long in the x-axis and short in the y direction. Unfortunately BlueKenue will not allow you to have different scale ranges on your axis (or if it does I have not been able to find a way), i.e. if you have increments of 5 on one axis you will have likewise on the other. I have included an image of the mesh I currently have to illustrate my problem. If I can construct this mesh in matplotlib I can then ensure my image is suitably clear.
My question is can I reproduce this mesh in Matplotlib in a relatively simple way? (I am fairly new to python). The mesh is a regular grid which has been triangulated.
Edit:
Mesh dimensions 29.76 x 2
x intervals = 0.16m (186 points along the x axis)
y intervals = 0.20m (10 points along the y axis)
Thanks