Drawing a smooth outline around points in a polar plot - python

Using matplotlib I have generated the polar plot below, which shows the angle and distance to aircraft nearby (calculated using the haversine formula). This plot is composed of 56132 individual points.
The code for this is almost the same as the examples from the documentation:
ax = plot.subplot(111, polar=True)
# Orient the plot with north (0 degrees) to the top
ax.set_theta_zero_location('N')
ax.set_ylim(bottom=0, top=100)
c = plot.scatter(r, t)
plot.savefig('test.png')
Where r is a list of radian angles and t is the corresponding distance.
I can also process the data and just draw the outline. To do this I converted all radian angles to 0-359 degrees, found the highest distance measurement and plotted the result with a line:
My specific question is: can I somehow draw a smoother outline around the points? Preferably filled with a gradient outward from the centre.
However if anybody can suggest general ways of making this data more visually appealing that would also be excellent.

If you are looking for a way to fill the area, you might consider a pseudocolor heatmap (pcolor), or a filled contour (contourf), which are available in matplotlib (For example: http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.pcolor). Getting them to work in this case might be tricky - you might need to convert your plot points to a rectangular grid in order for it to work.
Alternatively, you could try finding the several percentile values for each angle, (instead of just the largest) and draw multiple lines in different colors.

Related

How may I create a plot of a 2D lattice where the color between two points of this lattice is scaled to the distance between two points, in python?

I am incredibly new to python and I need help in plotting a figure like this
PLOT
Where it is figure of a 2D atomic lattice where the color of the segments scale according to the length of the segment. The input would be the XY positions of all the atoms.
Thank you for the help!

How to add black dot or circle dot as significance (p<0.05) over a spatial trend plots in python

I have calculated spatial slope and p_value using scipy.stats.linregress looping over individual pixels (lat*lon) along the time dimension. Now I can make spatial plot of slope value using plt.pcolormesh (lat, lon, slope).
But over it I want to add p_value<0.05 as dot mark wherever applicable to the same slope spatial plot. Similar to the below images.
Any help or remark regarding the same from the community............
Thanks
example_image
example_image
ax.pcolor(lon, lat, hatch, hatch='..', zorder=1, alpha=0.0, transform=ccrs.PlateCarree()) this worked for me!
Similar to Hatch area using pcolormesh in Basemap

Coloring 3D shapes

How is it possible to color a 3D shape /point cloud (in my case a human body), in such a way that each point has a different color but the color transition from point to point is smooth, as shown in the picture below?
The shape of N points is represented as an Nx3 array of point coordinates x,y,z. I tried to simply convert the coordinate values x,y,z of each point to r,g,b color values, but the result isn't satisfying (e.g. some points that are close to each other according to the Euclidean distance are colored by a similar color but they should be colored with different colors because their geodesic distance is large).
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
pc = ...
colors = (pc - pc.min()) / (pc.max() - pc.min())
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(pc[1], pc[1], pc[2], c=colors)
plt.show()
I found a way to do it which gives a satisfying result.
The idea is to color a sphere based on the coordinates of its vertices (as shown in the question). Such a coloring is nice because there are no problems with "Euclidean vs geodesic distance" as in human shapes.
Then, we can use Pytorch3D to deform the sphere to the input shape as described here. In this way the sphere coloring is smoothly transferred to the human shape. Although I have a point cloud with only vertex coordinates, the result is pretty good.
Below is an example of coloring a dolphin by using this method:
One problem is that we still need to transfer the coloring from the obtained shape to the original shape, something that perhaps could be done by finding nearest neighbors between the two (I haven't tried it though).

MatPlotLib rotate 3D plot around fixed axis

I am trying to rotate the following figure around the vertical green axis drawn:
However, I'm running into trouble trying to set the correct elevation and azimuthal values in order to correctly rotate my figure.
For example,
for i in range(0,360):
axU.view_init(100-i,-90+i)
plt.draw()
plt.savefig('./gif1/rot%i.jpg'%i,dpi=100)
gives me a figure like
http://imgur.com/b26d0V2
and
for i in range(0,360):
axU.view_init(100,-90+i)
plt.draw()
plt.savefig('./gif1/rot%i.jpg'%i,dpi=100)
looks something like:
http://imgur.com/3wdN8zT
both give me too much rotations around unwanted axes, where as I really just want to pan around the green axis drawn above. Is there any way to do this?
for i in range(0,360):
axU.view_init(100-i,-90)
plt.draw()
plt.savefig('./gif1/rot%i.jpg'%i,dpi=100)
This give me something similar to what I want, where the rotation is uniform around one axis, but this rotates around the horizontal green axis whereas I would like it to rotate around the vertical green axis.
rotation
http://imgur.com/b4zeUiI

How does the area of Matplotlib’s circular marker scale with its radius?

How does the area of the circular marker scale with the marker radius in Matplotlib? I would expect it to scale as pi times radius squared, but it does not.
I am trying to create a figure to show a closely packed distribution of N circles. This distribution happens to be regular (it is hexagonal) so it’s easy to know the locations of the centres of each of the circles. I plot these using matplotlib.pyplot.scatter(), using the circle marker from matplotlib/lib/matplotlib/markers.py for the circles.
Now in order to pack the circles closely, I need to set the area of the circular markers so that they precisely touch each other. I expect this to happen if I set the marker area to numpy.pi*(L/2)**2 where L is the diameter of each circle (in points), which is equal to the distance between two circles if they are to touch precisely. But this results in a plot in which the circles overlap. Here is the code that produces this plot:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
f = plt.figure(figsize=(7, 7), dpi=100)
ax = f.add_subplot(1,1,1)
ax.set_ylim(-105,105)
ax.set_xlim(-105,105)
L = 14.0 # Diameter of a circle in data units
# marker_radius is L/2 in points.
marker_radius = (ax.transData.transform((0,0))
-ax.transData.transform((L/2,0)))[0]
marker_area = np.pi*marker_radius**2
ax.scatter(x, y, color='#7fc97f', edgecolors='None', s=marker_area)
plt.savefig('figure.png',bbox_inches='tight')
Clearly the area of the circular marker in matplotlib/lib/matplotlib/markers.py does not scale as pi times radius squared (as it should). Upon trial and error, I found that it actually scales as roughly 2.3 times radius squared. When I set the marker_area to 2.3*marker_radius**2, I get a closely packed distribution as required.
I wonder if somebody could comment on why the circular marker size scales in this peculiar way. Also, what is the precise scaling? Is it really 2.3? Thanks!
I quickly tried this code (changing only the marker from s to o), and from that it seems that the square root of the marker size equals the diameter (in points, see the post I referred to) of the circle:
From the documentation:
s : scalar or array_like, shape (n, ), optional, default: 20 size in points^2.

Categories

Resources