Using a combined linear-logarithmic axis - matlab

Axis scaling in MATLAB can be either linear or logarithmic. But how can I combine both on a single axis? I'd like to scale part of my y-axis linear and part logarithmic.
The distribution function:
where I=1:.5:250; and my mu and sigma are both constant. This is the backward cumulative distribution of the function above
I plotted it using semilogx(I,(sum(f)-cumsum(f)/sum(f))), where f is the function above. Notice that the y-axis is linear.
This is the same curve but with my desired y-axis
where the y-axis is linear in [10, 90], but logarithmic in the intervals [0.01, 10] and [90, 100], resulting in a "zoom effect" in those ranges.
How can I combine linear and logarithmic scales on the same axis?

Related

3D kernel density plot in 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.

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?

MATLAB contour plot of 2D scatter

What I want to do is very simple, I just cannot seem to get MATLAB to do it. I would like to plot contours using my 2D data set.
My data set is large; 2 x 844240. I can do a scatter plot just fine,
scatter(Data(1,:), Data(2,:));
Reading through the forums I found Scatter plot with density in Matlab, where a hisogram was plotted. This would suffice, however, I would like to overlay the plots.
The issue is that they have different axis, my scatter data has an axis of [0 0.01 0 2500]; whereas the histogram is [0 100 0 100].
Is there a way to change the axis values of the histogram without modifying the image?
Thanks!
If I understand correctly, you are using hist3 to construct a histogram and then using imagesc to plot it. You can use the second output argument of hist3 to get the histogram bin centers, and then pass those on to imagesc, e.g.
nBins_x = 100;
nBins_y = 100;
[counts, bin_centers] = hist3(Data, [nBins_x nBins_y]);
x_bin_centers = bin_centers{1};
y_bin_centers = bin_centers{2};
imagesc(x_bin_centers, y_bin_centers, counts)
A couple other notes:
In your case, you will need to transpose your [2 x N] matrix when passing it to hist3, which expects an [N x 2] matrix.
imagesc puts the first axis (which I've been calling the "x" axis) on the vertical axis and the second on the horizontal axis. If you want to flip it, you can use:
imagesc(y_bin_centers, x_bin_centers, counts')
If you want to specify the histogram bins explicitly (e.g. to match your scatterplot) you can specify that in the arguments to hist3:
x_bin_centers = linspace(0, .01, 100);
y_bin_centers = linspace(0, 2500, 100);
counts = hist3(Data, {x_bin_centers, y_bin_centers};
And if you want a contour plot, you can use (note that contour takes the axes arguments in a different order than imagesc):
contour(x_bin_centers, y_bin_centers, counts');
If you are unhappy with the jaggedness of the contours, you may consider using a kernel density estimate instead of a histogram (check out ksdensity) (oops, looks like ksdensity is 1-D only. But there are File Exchange submissions for bivariate kernel density estimation).

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)