this is the graph in question and the dots should appear in the bottom plane, not "above" the plane like i manged to.
bx.scatter(xs,ys,zs, zdir=zs,c=plt.cm.jet(np.linspace(0,1,N))) # scatter points
for i in range(N-1):
bx.plot(xs[i:i+2], ys[i:i+2], zs[i:i+2], color=plt.cm.jet(i/N), alpha=0.5)
#plots the lines between points
bx.scatter(xs,ys,zs=732371.0,zdir="z",c=plt.cm.jet(np.linspace(0,1,N)),depthshade=True)
bx.set_zlim3d(732371.0,) #limit is there so that we can project the points onto the xy-plane
as youll notice the points are drawn above the xy-grid and I had to set a lower limit for the z-axis so that the first projected point will not interfere with the first scatter point
I would prefer the points be in 2d and less hacky since I got 50 other graphs to do like this and fine tune each one would be cumbersome.
Got some simpler method you want to share?
There are many options, and ultimately, it depends on the range of your data in the other plots.
1) Offset the projection point by a fixed amount
You could calculate the minimum Z value, and plot your projection a fixed offset from that minimum value.
zs=min(zs)-offset
2) offset the projection by a relative amount that depends on the range of your data.
You could take into account the range of your data (i.e. the distance from min to max Z) and calculate an offset proportional to that (e.g. 10-15%).
zs=min(zs)-0.15*(max(zs)-min(zs))
Related
We know that we can plot 3d graphs in MatPlotLib but in which field does it used and for what purpose
3D graphs are used when you need to establish the relationship between 3 variables(x,y and z).
This application can be used in the following fields:
1)geographical area: In this field X,Y is used as latitude,longitude and Z can be used as Altitude to replicate the geographical area like hills,buildings etc..
2)Geometry: To visualize the 3d objects like plane,sphere,cube etc in three dimensional space we use 3d plotting.
3)Statistics: To compare two variables on third variable we use 3d plots like 3d barchart, Scatter plot etc..
There are many other fields where 3d plotting is used instead of 2d plot, as it provides more information visually.
When you are working with 3 variables and want to plot a graph in between them and identify the relationship between them then you should use 3d graphs.
There can be many use cases of 3d plots:
To describe the position of a point in a plane if the position varies with time, we now need 3 measurements- x-axis distance, y-axis distance, and time elapsed.
To describe the position of a point in 3D space, we need 3 measurements: x distance, y distance and z distance.
To describe the position of a point in 3D space, if the position varies with time, we need 4 measurements: x distance, y distance, z distance and time.
Each of those measurements represents a dimension, and each dimension requires it’s own axis.
Follow this docs for more information
r = np.linspace(0.1,1,11)
theta = np.linspace(-alpha,alpha,11)
radius_matrix, theta_matrix = np.meshgrid(r,theta)
u_radial = -q*(1/radius_matrix)*u_sol[0]
u_theta = theta_matrix*[0 for x in range(len(u_sol[0]))]
ax = plt.subplot(111, polar=True)
ax.plot(theta_matrix, radius_matrix, u_radial, u_theta) #color='r',
ls='none', marker='.'
plt.show()
I am trying to make a plot of a velocity field (same as vector field) using numpys quiver function. The velocity field is written
where q is just an arbitrary constant and r is the distance to the origin. Now, to plot this in a polar coordinate system I create two meshgrids radius_matrix and theta_matrix, as seen in my code (line three). Together these meshgrids form a polar coordinate plane, with r on the horizontal axis and theta on the vertical axis (at least I think) and each point should have a vector arrow corresponding to the equation above.
So for that to happen I define u_radial and u_theta, which are the vector components in radial and angluar direction, resp.. The variable u_sol[0] contains f(theta) (as seen in the equation) for 11 different theta points, and I thought that this would give the correct vectorcomponent, but it doesnt. Why not?
I am expecting something like this, that the arrow shrinks when I get close to the edge for a single value of r. I just want this but for more values of r. This is the data of my u_sol[0] vector:
u_sol[0] = [4.68520269e-26 1.54380741e+00 2.74550730e+00 3.60503630e+00
4.12217780e+00 4.29651250e+00 4.12741184e+00 3.61407419e+00
2.75560427e+00 1.55113610e+00 3.84028608e-18]
When I plot this, I get something worse, see the figure below. What happend to the arrows? And why are there colors all of a sudden?
Best regards SimpleP.
I have a set of graphs from which I want to find an outline graph (Black line in this figure.)
Finding the maximum of each graph at all points on the x-axis is not possible because the x-values are not same for all the graphs. The points are accurate to a couple of decimal places. this figure might be able to help understand better.
I tried converting each graph to a polygon and using shapely cascaded_union and then cropping off the bottom.
It works for a small number of graphs, but when the number of graphs becomes large. It takes a lot of time.
Is there some other efficient way to do this?
Sort all your points by their x coordinate.
Your final output will have a finite number of pixels. You can compute the range of x values that fall within each pixel(small range but not 0). So split your points into buckets. Since they are already sorted, you just need to advance through the list until the values belongs to the next range.
For each pixel column compute the maximum y value you find. Add a point at the (x, y) for the black line.
The complexity of this will be o(N logN).
If you have gaps on the x axis you can choose to either skip it and have a gap in the black line or simply interpolate between the neighbouring values. If you plot the blackline as a collection of line segments you can just skip generating a point for that column and let the renderer do the interpolation for you.
If your original points are too rare (they skip pixels) your line may look jagged (jumping up and down). You can avoid this by adding interpolated values for the functions that don't have a point in that range. Linear interpolation should work just fine. Make sure you generate try to generate a point at the beginning and the end of the interval and take the larger y-value.
I have an issue that I can't seem to solve. I have already acquired data from another source and created 2 polynomials that are identical in shape but not in orientation, that is one is rotated x degrees compared to the other, and if you rotate the graph x degrees back they will match.
I have already taken the derivative of both of the graphs at a certain point.
I would like to graph these slopes onto a unit circle on a polar graph, and somehow find the angle difference between these two line segments of slope i and j that extend from the origin.
I'm fairly new to python so I so not know how to begin plotting these in polar or finding a way to determine the angle difference. I know that by hand, you can take the inverse tangent but that will only give you a range from +90 to -90. I would like my number to fall in the range from 0 to 360 for rotation.
Any help is appreciated. If this isn't enough info or if it isn't clear enough I can provide more.
I have a data set that I want to plot as a quiver plot. The set contains parameters of stars represented as ellipses (center, long axis length, short axis length, bearing (angle) of the long axis) that I want to draw as a vector field with quiver plot. The data (axis lengths and bearings) is noisy and I need to smooth it. While smoothing works fine for axis length I'm stuck with angle smoothing. The problem here is that any ellipse is visually (and for my purposes too) equivalent to an ellipse rotated by 180 degrees and ellipses' angles are distributed in the range from 0 to 180. Smoothing for the most part of this range works fine except for corner cases where angles are close to 0 and close to 180. While two ellipses with angles close to 0 and close to 180 looks visually similar, their "average" has an angle of 90 degrees which is clearly wrong. See an example of unsmoothed data (white stars and green arrows representing these stars) where the smoothing breaks. To be clear I don't need the direction of the arrow, and in my final plot I'm hiding arrow heads. I need only the angle/bearing of it and the average of two angles of 179.9 and 0.1 needs to be either 180 or 0 but not 90.
Any idea how to approach the problem?
Two options:
First, you can convert your angle to an int and expand it to the full range of that int and take advantage of overflow. For example:
np.astype((ang-180.)/360.*65536, 'uint16')
This may work if your smoothing function is simple and doesn't have comparison operators in it and is in my opinion a nasty hack.
Second, rotate your angle by some arbitrary amount, and do the smoothing multiple times, picking the best answer.
I would smooth the original, then rotate by 120, smooth that, rotate by 240, smooth that. Then un-rotate and then keep only the angles that agree. Of course this comes with a 3x+ performance hit.
Edit:
Third option: Smooth the vector components.