Contour plot of xyz format - python

I am still struggling with this guys, I have tried the suggestion on this post already. I think my brain isn't working well so I really need a dumbed down answer:
So I have data in the format of a matrix i.e.:
[x1,y1,val]
[x1,y2,val]
[x1,y3,val]
[x1,y4,val]
[x1,y5,val]
..........
[x2,y1,val]
[x2,y2,val]
[x2,y3,val]
[x2,y4,val]
[x2,y5,val]
where val is some number. Basically I want to plot a contour using this and have tried using a number of examples as a starting point but am still unsure of how to proceed. I want something of this kind:
http://www.astro.ex.ac.uk/people/mbate/Animations/Stellar/pgplot_0259_outflow.png
where the x and y are the RA and DEC. Thanks!

Related

Multiple functions plotted as f(y) instead of f(x) in pandas

I'm new to Python so I hope you'll forgive my silly questions. I have read a dataset from excel with pandas. The dataset is composed by 3 functions (U22, U35, U55) and related same index (called y/75). enter image description here
now I would like to "turn" the graph so that the index "y/75" goes on the y-axis instead of the x-axis, keeping all the functions in the same graph. The results I want to obtain is like in the following picture enter image description here
the code I've used is
var = pd.read_excel('path.xlsx','SummarySheet', index_col=0)
norm_vel=var[['U22',"U35","U55"]]
norm_vel.plot(figsize=(10,10), grid='true')
But with this code I couldn't find a way to change the axes. Then I tried a different approach, so I turned the graph but couldn't add all the functions in the same graph but just one by one
var = pd.read_excel('path.xlsx','SummarySheet', index_col=False)
norm_vel2=var[['y/75','U22',"U35","U55"]]
norm_vel2.plot( x='U22', y='y/75', figsize=(10,10), grid='true' )
plt.title("Velocity profiles")
plt.xlabel("Normalized velocity")
plt.ylabel("y/75")
obtaining this enter image description here
I am not very familiar with dataframes plot. And to be honest, I've been stalking this question expecting that someone would give an obvious answer. But since no one has one (1 hour old questions, is already late for obvious answers), I can at least tell you how I would do it, without the plot method of the dataframe
plt.figure(figsize=(10,10))
plt.grid(True)
plt.plot(var[['U22',"U35","U55"]], var['y/75'])
plt.title("Velocity profiles")
plt.xlabel("Normalized velocity")
plt.ylabel("y/75")
When used to matplotlib, in which, you can have multiple series in both x and y, the instinct says that pandas connections (which are just useful functions to call matplotlib with the correct parameters), should make it possible to just call
var.plot(x=['U22', 'U35', 'U55'], y='y/75')
Since after all,
var.plot(x='y/75', y=['U22', 'U35', 'U55'])
works as expected (3 lines: U22 vs y/75, U35 vs y/75, U55 vs y/75). So the first one should have also worked (3 lines, y/75 vs U22, y/75 vs U35, y/75 vs U55). But it doesn't. Probably the reason why pandas documentation itself says that these matplotlib connections are still a work in progress.
So, all you've to do is call matplotlib function yourself. After all, it is not like pandas is doing much more when calling those .plot method anyway.

How to transform the "multi_hand_landmarks" to "numpy array"?

I've been working on a program for hand pose recognition with Python.And there is an class named "multi_hand_landmarks" , which contains 21 3D hand-knuckle coordinates.Each coordinates is showed like this:
enter image description here
Now I'm going to calculate the coordinates of the midpoint between two joints,but I've failed to transform these data to any other type,here is my problem.
It's solved.I used to consider the "landmark" as List,but actually not.
If you want to get the x-coordinate of a joint,you should code like this:
hand_feature= hander.process(img)
for landmark in hand_feature.multi_hand_landmarks:
x=landmark.landmark[0].x # You can replace the "0" with any number you want
print(x)
It's extremely a pain in the ass that we should code "landmark.landmark[0].x" rather than "landmark[0].x" !

How to understand this number with "double scientific"-notation (~1e-9-4.999e-1) in matplotlib

I'm running a calculation that outputs a matplotlib plot with a vertical axis scaled with (see image below).
~1e-9-4.998e-1
This is very weird scaling and I'd like to make sure I understand the notation correctly. Does it mean the following?
0.000000001 - 0.4998 = -0.499799999
So far I haven't been able to successfully google this. I would really apprechiate if someone could help me clarify this.
#Lagerbaer is right. The first number (1e-9) is the scale of the axes, and the second is a shift. So the tick marked -8.25 really means (-8.25)*1e-9 - 4.9984827e-1, or -0.00000000825 - 0.49984827 = -0.49984827825

Subtracting angles of complex valued matrix

Let's say I have two complex images Z_1 and Z_2. I want to make a relative-phase map of the second image with respect to the first. This means:
Z_2_relative = Z_2 * np.exp(-1j * np.angle(Z_1))
This creates a new complex valued matrix where the complex-phase should now be given by
np.angle(Z_2_relative) == np.angle(Z_2) - np.angle(Z_1)
But according to python these two are not equal. I bet it has something to do with the np.angle function.. but I cant pinpoint it, or know how to fix it...
PS: Sorry, cant make a reproducible piece of code atm. Can do it later today
Bah.. stupid question. Sorry for anyone that read it. If you do module 2pi, then everything is the same

python to identify curved segments

I posted a similar question on the ESRI forums, but the posting seems to have gone cold :(
Anyone know how to identify if an ESRI feature class contains curved, (arcs) segment(s)?
I have several thousand feat. classes, something via python would be great!
thanks!
Edit: update
someone at esri has commented that you can detect if a polyline feature contains an arc segment by comparing the "truecentroid" and "centroid" of the feature. if truecent. <> cent: then the feature contains an arc. This is OK, but I'm still lacking a solution for polygons, as the above method does not work.
Here's what we have so far:
lstFCs = arcpy.ListFeatureClasses("*", "Polyline")
for fc in lstFCs:
rows = arcpy.SearchCursor(fc)
print fc
for row in rows:
type = row.Shape
geom = str(type.centroid.X)
truegeom = str(type.trueCentroid.X)
if geom != truegeom:
print row.ObjectID
del row, rows
For the polygons I think you have to first loop through the rings of the polygons to find polylines and then you can examine the polylines as you do in your code.
Sorry I cannot help you any further since I don't have ArcGIS installed (and it is all long time ago I worked with ArcGIS). You might get better response on gis.stackexchange.com.
Try something like this:
import arcpy, json
arcpy.env.workspace = r"..." #Your database
lstFCs = arcpy.ListFeatureClasses("*", "Polyline")
for fc in lstFCs:
rows = arcpy.SearchCursor(fc)
print fc
for row in rows:
jsonGeometry = json.loads(row.Shape.JSON)
if 'curve' in jsonGeometry or 'curveRings' in jsonGeometry:
print row.ObjectID
del row, rows
There is a standard function in Geospatial SQL that is useful for what you want to do. It is called ST_CurvosityIndex(LineString). Applied to a feature LineString gives it an index number between 1-0. 1 means a straight line, 0 a string of lines that have start and end points at the same coordinate.
Unfortunately, I couldn't find any other information on how the algorithm behind this SQL/MM statement was implemented, but I think you can email Alessandro Furieri a.furieri#lqt.it, who developed that SQL statement, asking him about the algorithm that distinguishes how curved the LineString feature is.

Categories

Resources