I have plotted a dot raster plot divided into various segments, which I would like to label. In my case, I have different attenuation values for the same frequency value and want to label the attenuation values in the y-axis.
It's a little unclear exactly what your trying to do but if you mean to label the entire axis using:
ylabel('sometext','fontsize',12);
If you mean to label specific ticks on the axis try using something like :
set(gca,'Ytick',[0:3],'YtickLabel',{'hello','world','foo','bar'});
Edit:
You would want to do something like this.
set(gca,'Ytick',[1:20:120],'YtickLabel',{'label1','label2','label3',etc...});
Related
I currently have a vector field that looks something like this, generated with the following basic structure, where Z is some matrix:
[X,Y] = meshgrid(x,y)
[grad_x, grad_y] = gradient(Z)
quiver(X,Y,grad_x,grad_y)
I would like for this plot to be rescaled, such that the x-axis ranges from 1.5 to 3.8 and the y-axis ranges from 100 to 250, but for the arrows themselves to look identical. The only difference in the figure should be the axes labels.
I have tried:
grad_x_rescaled = [(grad_x - min(grad_x))./(max(grad_x)-min(grad_x))].*(3.8-1.5);
grad_y_rescaled = [(grad_y - min(grad_y))./(max(grad_y)-min(grad_y))].*(250-100);
But the problem with this is that although the grad_x and grad_y get rescaled overall, the scaling of the arrows themselves relative to each other are not conserved, and results in below (note the thick black streaks are presumably arrowheads, but the important thing is that the direction and relative sizes of the arrows are not exactly like in the first case.
Is there a matlab function or an expression to renormalize data into a new range, but such that the renormalized data is scaled relative to itself (such as the arrows should be scaled the same relative to one another)?
To simply change the axes tick labels you could use Matlab's ability to specify tick marks and tick labels. Basically you would just tell Matlab where to put the ticks and what the labels should say like this:
xticks(linspace(0,1,6))
xticklabels(linspace(1.5,3.8,6))
yticks(linspace(0,1,6))
yticklabels(linspace(100,250,6))
I have a given data set, and I want to compare the histograms of this data when represented as a bar histogram and a line histogram. Specifically, I want to use
myhist = histogram(mydata)
to get the bar histogram, and plot on the same figure a line histogram using
mylinehist = plot(myhist.Values)
However, when I do that, I get the following figure
It seems like the line histogram mimics the shape of the bar histogram, but offsets it by a certain amount on the x-axis. Is there a way to align the two so I can have them overlapping? I tried using a command like
align([mylinelist,myhist],'Left','None')
but to no avail. Thanks!
You need to specify the x-axis values for your line plot. These should be the midpoints of your histogram bins.
Try:
midpts = myhist.BinEdges + (myhist.BinWidth / 2);
plot(midpts(1:myhist.NumBins), myhist.Values);
I'm trying to create a 24x366 heatmap using imagesc with the x-axis labelled at 13 evenly spaced points as {'jan 15','feb 15',...,'dec 15','jan 16'}, and the y-axis labelled at every row from 1 to 24, like this:
Desired imagesc axes
When I run the script, it displays the y-axis as I want it, but it only displays the first label on the x axis and ignores the others. I can get this to work for a plot, but I can't get it to work for an imagesc. I've included my script below. Does anyone know how to make the imagesc display all 13 labels on the x-axis at evenly spaced intervals?
mylabels = {'jan 15','feb 15','mar 15','apr 15','may 15','jun 15','jul 15','aug 15','sep 15','oct 15','nov 15','dec 15','jan 16'};
testspacing = (1:(60*24*30):528480);
figure
imagesc(rand(24,366))
set(gca,'XTick',testspacing,'XTickLabel',mylabels,'XTickLabelRotation',45,'YTick',1:24,'YTickLabel',1:24)
The problem with your code is that your only one of your ticks from testspacing falls in the range of the plot testspacing=[1 43201 ...]. You can check the range of your x-axis by running xlim without any arguments.
You can rescale testspacing to fit your x-axis e.g. like:
xmax = 366;
mylabels = {'jan 15','feb 15','mar 15','apr 15','may 15','jun 15','jul 15','aug 15','sep 15','oct 15','nov 15','dec 15','jan 16'};
testspacing = (1:(60*24*30):528480);
testspacing = testspacing/max(testspacing)*xmax;
figure
imagesc(rand(24,xmax))
set(gca,'XTick',testspacing,'XTickLabel',mylabels,'XTickLabelRotation',45,'YTick',1:24,'YTickLabel',1:24)
or you just generate testspacing properly. Since you are putting own labels on the axis anyway you might just choose use testspacing = [0:30.5:366] or testspacing = [0:30:366] depending on what you want. This will also help you debug your own code later on.
On another note you should think about reducing the number of labels in general and decide which of the labels are really helpful. Maybe every 2nd or 3rd month is enough. You can "remove" individual labels by setting them to empty strings ''.
I have a vector which gives the speed of a rat over time. Could someone please help me on how I can show this data with a "color map" or "color bar". Basically I want to show each data point with a color.
As what Suever suggested, using imagesc is perfectly fine for your purposes. You can also add in a colour bar to give meaning of the mapped colours to the values in your vector. The y-axis won't have any meaning as you'll want to concentrate on the colours themselves. Therefore, you'll want to blank out the y-axis by grabbing a handle to the current axes in the plot and just setting the y-axis labels to blank.
As such, do something like this assuming that your data is stored in the vector data:
data = rand(1,100); %// random dummy data - 100 element vector
imagesc(data);
colorbar;
set(gca, 'YTick', []);
We get this image now:
Note that the colour bar on the right is scaled using the lowest and highest values in your data. The colours will be scaled so that it conforms to this lowest and highest value.
I have some datas, say from [0.1:0.1:0.9]+[1:1:10].
If I use scatter to plot it, it looks like this.
However, it want the points equally distribute along the axis, anyone can tell me how to do it? What I mean is the distance between data points in [0.1-0.9] are the same with [1-10] on the graph respect to x-axis.
If your data is contained in vectors x and y, use
plot(y,'o')
instead of plot(x,y,'o') or scatter(x,y).
If you want to label the x axis, use something like
set(gca,'xtick',1:length(y),'xticklabel',[.1:.1:.9 1:10])
Or you might want a subset of the labels, for example:
set(gca,'xtick',1:2:length(y),'xticklabel',[.1:.2:.9 2:2:10])