project data defined on a sphere - matplotlib

I have some data defined on a sphere (a sphere not the earth): is it possible with Python 2.6 and matplotlib to draw them on map (of the type of Mercator map) "automatically" or do I have to project the data?
Edit: All of my data are lat-long.

It really depends on what you have and what you want: x-y and/or lat-lon? It looks like your question is similar to a problem I had and more-or-less answered:
matplotlib and apect ratio of geographical-data plots

Consider using set_aspect(), using the reciprocal of the mean latitude of your data.
See matplotlib and apect ratio of geographical-data plots for a working example.

Related

Why do we use crs.PlateCarree() instead of crs.Geodetic() when using Matplotlib and Cartopy to plot a map based on lat and lon?

I've been learning how to use Cartopy and Matplotlib to plot map. But I have a question regarding the argument transform. According to the Cartopy document, transform specifies "what coordinate system your data are defined in". Suppose I am going to plot temperatures of an area, and the area has been split into several grid cells. Each grid cells has a corresponding coordinate defined in lat and lon (Geodetic Systems). Based on the Cartopy document, I need to use crs.PlateCarree() instead of crs.Geodetic(). I'm a bit confused about it. Because,I think the PlateCarree is a way of projection. In other words, coordinates defined in PlateCarree projections are projected data. But latitude and longitude should be unprojected data. Can anyone help me with it? Thanks!

A plot describing the density of data points in 2D space in Julia

I am trying to use Julia to create a gif animation showing the change of density of data points with time (the data points are at the beginning concentrated at the center, and than spread to the sides, a little bit like 2D Gaussian of variance increasing with time). I have checked a catalogue of available kinds of plots in Julia:
http://docs.juliaplots.org/latest/examples/gr/
And I have tried contour plot, heatmap and 2D histogram. However, it seems that the grids of a heatmap or a contour plot have to be manually specified which is highly inconvenient. A 2D histogram serves the purpose better, but it's more related to the number of data points and when I want the plot to be more continuous by setting more bins, it cannot describe the density of data points well. Are there any good substitutes of the 2D density plot in matplotlib in Julia as the following?
https://python-graph-gallery.com/85-density-plot-with-matplotlib/
You use a package like KernelDensity to calculate the point density, then plot that. Here's an example
using StatsPlots, KernelDensity
a, b = randn(10000), randn(10000)
dens = kde((a,b))
plot(dens)
The philosophy, in the Plots package and other places in Julia, is that you generate the object you are interested in first, and then dispatch takes care of plotting it correctly.
Alternatively, you can always use PyPlot to plot anything using matplotlib directly.

Selecting a single color from a matplotlib colormap in Juila

I'm constructing a graph plot in Julia and need to color each edge of the graph differently, based on some weighting factor. I can't find a way to get a specific RGB (or HSV, it doesn't matter) value from a colormap. Let's say I'd like to get the RGB value on 'jet' that would correspond to a data value of n on imshow plot.
In python, I would just use jet(n), where n is the value along the colormap in which I am interested. PyPlot in Julia doesn't seem to have wrapped this functionality. I've also already tried indexing into the cmap object returned from get_cmap(). Any advice?
I'm stumped, so even an approximate solution would help. Thanks!
Maybe you can look at the Colors.jl package (https://github.com/JuliaGraphics/Colors.jl):
using Colors
palette = colormap("Oranges", 100)
Then you can access each color with palette[n]. Or are you using PyCall? A code describing what you're trying to do would help.

Contour diagram for Pandas and/or Seaborn for a 3-column matrix

I have like 400 data points which are in forms of a 3-tuple. Something like this:
[[1.2, 3.4, 7.8],
[3.1, 2.6, 3.4],
...
]
Each row is a 3-tuple point, (x, y, z) which shows a point in 3D space.
What I want to do is drawing a contour diagram using these values in the form shown in https://en.wikipedia.org/wiki/Contour_line.
I want this:https://en.wikipedia.org/wiki/Contour_line#/media/File:Contour2D.svg.
I want the third dimension (z) to be the source for contours.
I have seen some other examples on the net, but they are so confusing. They are relying on a function to draw the diagram which is not in my case. I am representing the function as a matrix.
I hope I give enough information to let you know what I am looking for.
Thanks guys.
You can try conrec algorithm from Paul Bourke. It's implemented in many languages and also good explained. It uses the marching cube algorithm.

How can I plot this kind of picture using Matplotlib or Mayavi?

I have three 2d arrays: X,Y,Z, which contain irregular 3d points coordinate,respectively.And another 2d array data, which contains the values on those points.
What I want to do is to display this data in 3d space , with 0 value part masked out.Much like this one:
In matlab, I can use function fill3 to achieve this, but how can I plot the same kind of picture in matplotlib or mayavi ? I have tried to use mask array ,plot_surface and colorface together, as the example here:
Plotting a masked surface plot using python, numpy and matplotlib
and it worked, the result is the link below:
but that is really really slow, and will cost too much time. Is there a better way?
Well, today I find out an alternative way to solve the problem. Except using plot_surface, I choose to use scatter3D,
the core code is some what like this
aa=np.shape(X)[0]
bb=np.shape(X)[1]
x=X.reshape(aa*bb)
y=Y.reshape(aa*bb)
z=Z.reshape(aa*bb)
data=data.reshape(aa*bb)
x1=[]
y1=[]
z1=[]
da1=[]
for i in range(aa*bb):
if data[i]>0:
x1.append(x[i])
y1.append(y[i])
z1.append(z[i])
da1.append(data[i])
my_cmap=cm.jet
my_cmap.set_over('c')
my_cmap.set_under('m')
N=da1/max(da1)
fig=plt.figure()
ax=fig.add_subplot(111,projection='3d')
ax.scatter3D(x1,y1,z1,s=6,alpha=0.8,marker=',',facecolors=my_cmap(N),lw=0)
and the result is like this:
this doesn't really solve the problem, but it is a nice substitution.
I'll keep waiting for more answers.