3d scatter plot with mplot3d with missing frequency as z axis - matplotlib

I am trying to plot some data but I only have my x and y axis given. I would like to get the frequency for my z axis like I would in a histogram. But I don't really want a histogram, rather a scatter plot or a surface plot.
This is my histogram right now, quite messy.
Is it possible to use the function of the histogram to get the frequency of the points but have a scatter/surface plot instead? Or to change the bars of the histogram to something like dots or something similar?
None of my data points have the same value, so I would like them to be sorted in intervals, like [0,0.05] or so, that's why I am trying to find another solution than calculating this.

Related

Matplotlib: Add contour plot to base of surface plot python

So I've produced a 3-d graph on python using trisruf:
ax.plot_trisurf(x,y,z)
and I end up with the following:
3d plot
So now I want to plot contours on the base of this same plot, When I tried using ax.contour(x,y,z) I get an error saying my z should be in 2-dimensions, however my data comes from three 1-d arrays.
How can I go about plotting contours on the base of my graph?
Ok so I managed to find the answer after a bit of searching,
ax.tricontourf(angle_x,angle_y,nlist,zdir='-z', offset = -0.859, cmap='coolwarm') worked, its important to make the offset just slightly lower than the lowest z point (or whatever direction you want the projection) so you can actually see the contour plot!
Here's the result:
updated plot with contour

how to make x axis as year-month in time series plot with matplotlib?

I wanna make time series plot so I tried.
ut it seems like it detected 2011.01 as a number when I check the outcome plot.
How can I code to make it detect as a year-month not number??

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.

Using matplotlib to plot a matrix with the third variable as source for a color map

Say you have the matrix given by three arrays, being:
x = N-dimensional array.
y = M-dimensional array.
And z is a set of "somewhat random" values from -0.3 to 0.3 in a NxM shape. I need to create a plot in which the x values are in the x-axis, y values are in the y-axis and using z as the source to indicate the intensity of each pixel with a color map.
So far, I have tried using
plt.contourf(x,y,z)
and the resulting plot is very nice for me (attached at the end of this paragraph), but a smoothing is automatically applied to the plot! I need to be able to distinguish the pixels and I cannot find a way to do it.
contourf result
I have also studied the possibility of using
ax.matshow(z)
in order to sucesfully see the pixels... but then I am struggling trying to personalize the x and y axis, since only the index of the pixel is shown (see below).
matshow result
Would you please give me some ideas? Thank you.
Without more information on your x,y data it's hard to know, but I would guess you are looking for pcolormesh.
plt.pcolormesh(x,y,z)
This would take the x and y data as input and hence shows the z data at the appropriate coordinates.
You can use imshow with the keyword interpolation='nearest'.
plt.imshow(z, interpolation='nearest')

converting diurnal scatter plot into heatmap plot

I have created a diurnal plot of date vs. time but it is rather messy and I'd prefer to create a heatmap. Something similar has been done here, but it doesn't work as I can't parse the time in as well. I tried this which works for the x-axis but I can't do the y.
Ideally, it would have a legend on the size showing how much data is in each 2D bin. How do I parse the x and y axis in such that numpy.histogram2D/imshow can read it or meshgrid/pcolormesh can be used?