3D kernel density plot in matlab - matlab

I have differences between hourly temperature and average temperature data from 1991 to 2021.
I would like to plot 3D plot with ksdensity. Suppose that x= axis of year, y = axis of temperatrue differences from mean temperature, z= densities. How to generate a 3D kernel density plot?
Here is the code of plot 2D kernel density.
[f,xi] = ksdensity(TP_ym);
plot (xi, f, 'LineWidth',1)
Here is the temperature data.

Related

MATLAB Surf plot with bins

I have a nxm matrix where n is the number of bins in the x axis and m is the number of bins in the y axis. Each position in the matrix has a number which shows how many data points are in matching x-y bin ranges from my raw data and when surf plotted results in a density plot.
The problem is if I have 100 x-bins and 50 y-bins the axis of my surf plot will be 0-100 on the x-axis and 0-50 on the y-axis. Which makes sense because I am doing surf(Matrix).
But infact I want the x and y axis to be from 0-5 for example. Therefore the number of bins for x and y will determine only the resolution of the plot. Low number of bins = low resolution. High number of bins = high resolution. When for the whole time the axis of the plot are 0-5.
In a nutshell is it possible to plot a matrix of varying size that is used for a surf plot into pre-assigned axis values?
(Of course doing axis([0 5 0 5]) will not work)
Found it difficult to word the question but hopefully it makes sense.

How to create 3D Histogram with Percentage on Z Axis

I want to create 3D histogram with percentages on Z axis. I used hist3 function, but it only creates histogram with frequency on Z axis. Can someone please help me to change frequency to percentage in the hist3 function?

Creating a plot with a non-linear X-scale, Matlab

I'm trying to create a plot using the values 10^0 10^3 10^6 10^9... on the x-axis. Matlab does not automatically rescale so my values are all down in the left corner.
My current code is:
figure('name','My plot title');
hold on
plot(kap, reg, '--mo');
plot(kap, reij, '-.r*');
hold off
kap is a vector of x values -> 10^0 10^3 10^6 10^9.....,
reg and reij are measurements.
Maybe loglog, semilogx could help?
A picture of my plot: enter link description here
The problem was that I should use loglog or semilogx and not use it in a figure.
Yep, semilogx is what you want:
semilogx(kap,reg,'--mo');
loglog gives logarithmic scales for both x and y axes, and semilogy plots with a lagarithmic scale on the y axis.
x=10.^(0:3:30);
y=rand(size(x));
semilogx(x,y)

How to plot polar with data in matlab like this picture

I have data representing frequency and decibels, and I want to make a polar like this picture:
What is the command for this?
On MathWorks:
The polar function accepts polar coordinates, plots them in a Cartesian plane, and draws the polar grid on the plane.
polar(theta,rho) creates a polar coordinate plot of the angle theta versus the radius rho. theta is the angle from the x-axis to the radius vector specified in radians; rho is the length of the radius vector specified in dataspace units.
You should be able to get your result with polar(decibels, frequency).

3d plot with given 2d data

I want to understand how the 2d data is related to z axis to get the 3d plots
let us say that i have x=[-1:0.1:1], vector
and y=[1 2 3 4 5 4 3 2 1 0]
a plot of y Vs x will have peak of 5 and slope down to both sides at x=0.5
how to relate these data in 3d to get the bell shape surface, with similar characteristics.
You can view a line/curve plot as a function of a single variable, y=f(x), and typically, x and y are both vectors. For e.g., you can plot the Gaussian bell curve as
x=linspace(-3,3,1000);
y=exp(-x.^2/2);
plot(x,y)
A surface plot, on the other hand, is a function of two variables, z=f(x,y) where x and y can be either vectors or matrices and z is a matrix. meshgrid is a very handy function that generates 2D x and y arrays from 1D vectors by proper replication.
It is the z matrix that you plot either as a 2D image (values of z are represented by colors) or a 3D plot (values of z are represented as heights along the z-axis). For e.g., a 3D Gaussian bell curve can be plotted as
x=linspace(-3,3,1000);y=x'; %'
[X,Y]=meshgrid(x,y);
z=exp(-(X.^2+Y.^2)/2);
surf(x,y,z);shading interp
This is how the respective plots should look like