MATLAB: colorbar on mapping tool based on point feature - matlab

Hi,
I could able to plot points on the map using geshow function based on value. I need to show a continuous stretched colorbar depicting these values. I don't know how to get so. The colorbar in right doesnot represent these values in the map. Please suggest me how to get so. Thanks!

You can put your own tick label on the colorbar, for example :
colorbar('Ticks',[0, .2, .4 , .6, .8, 1],...
'TickLabels',{'val_1,'val_2','val_3','val_4','val_5','val_6'})
Here, 'Ticks' are values on the colorbar itself, and 'TickLabels' are values (must be represented as strings) that you wish to display instead.

Related

Matlab date help on x-axis

I have a porkchop plot that looks similar to this:
The contour function used to make it has input arguments for the x and y positions that are serial dates (as that seemed to be required by MATLAB). Then I used the following command to get the format I want:
datetick('x', 2); datetick('y', 2);
The problem I am having is that when I zoom in on the plot the tick labels to not autogenerate and I can be left with no ticks on the x or y axis if I zoom in to use a weeks' date range for example.
I tried enabling 'auto' for XtickMode and YtickMode but when I zoom in or pan after using those commands the relationship between the independent and dependent variables are lost for some reason (aka the dates don't stay with data like they do when you just have numbers on the x axis and zoom in).
Any ideas on how to solve this issue to get the functionality I'm looking for?
I have also tried the command xtickformat('dd-MMM-yy') but I get an error "Invalid numeric tick label format." when I use it with the contour plot.
As far as I know there is no builtin method in MATLAB to do this. I use the datetickzoom function from the MATLAB FileExchange. If you replace all instances of datetick with datetickzoom, it will automatically update the relevant axis labels when you zoom in.

Visualizing 1D data in MATLAB

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.

Set legend from looped data points matlab

I would like to scatter plot different sets of data points. Each point should have a different markerfacecolor, but within a given set, they would all have the same markeredgecolor.
I got this to work by looping over single scatter points individually, because markerfacecolor seems to only be able to take scalar points. The way I do it is that I loop through my data, and look for the appropriate color.
This works fine because I can define each point separately, but it becomes a problem when trying to set up the legend. It tries to list all the different points, but what I'd like is just an empty circle (markerfacecolor white or transparent), with each set having their specific markeredgecolor.
I hope this is clear enough. Thank you.
Mike
I've had luck using patches, setting 'FaceColor', 'EdgeColor' to 'none', 'MarkerEdgeColor' to 'flat' and setting the 'FaceVertexCData' to a Nx3 matrix where each row is a color corresponding the the points specified by you Nx1 'XData', 'YData' and 'ZData'.
h = patch('parent',gca,...
'XData',x,...
'YData',y,...
'ZData',z,...
'FaceColor','none',...
'EdgeColor','none',...
'MarkerFaceColor',faceColor,...
'MarkerEdgeColor','flat',... This is what sets the Edge of each marker
'FaceVertexCData',C) % C is a Nx3
I don't have access to Matlab at the moment, and Octave does not seem to have exactly the same functionality. Check out the Matlab patch properties documentation for more information.

Axis commands changes TightInset property to zero

I use some things from this question get-rid-of-the-white-space-around-matlab-figures-pdf-output to get rid of the white space when saving figure plots and images. This works fine, but my problem is when I use commands like "axis square" or "axis image". Ivt sets TightInset property of corresponding axes to 0 in "y" direction. I mean when I use this:
inset=get(a,'TightInset');
second and fourth numbers in "inset" are always zero, even if I set title and x-label. So in the end I don't see plot titles and x-labels.
Can I fix it somehow? So far I do it manually by adding some suitable number, but it is not convenient.
EDIT: Some more code for example. It displays two histograms.
h=figure;
subplot(121)
bar(bins,histogram1,'hist');
axis square
title('Historgram 1');
xlabel('Intensity');
ylabel('Pixel count');
set(gca,'xlim',[0 1])
subplot(122)
bar(bins,histogram_out,'hist');
axis square
title('Histogram 2');
set(gca,'xlim',[0 1])
xlabel('Intensity');
ylabel('Pixel count');
and if I call
a=get(h,'Children');
for i=1:length(a)
inset=get(a(i),'TightInset');
%...some stuff here
end
those y-related numbers in inset are zeros. If I comment axis square and do this, then inset are correct and it does what I need.
As far as I know when you use 'TightInset' you'll get only the graph or image, axis will be removed. I downloaded a function from mathworks file exchange 'saveTightfigure.m' to solve a similar problem. But I did not needed axes. If you need axes may be you can edit limits set inside the function. I mean you can give a little more space at left and bottom for keeping the axes.

How to change the format of the numbers displayed on an axis in a MATLAB plot?

I actually have 3 questions:
I have a plot with data that is in the thousands and my plot's axis is diplaying the tick marks as .4 .8 1.0 1.2 and a *10^4 in the lower right. This is a little annoying.
Besides dividing my data by 1000 or hardcodig the tick marks is there a way to change to tick marks from .4*10^4 TO 4000?
Seems like this should be trivial but aftter browsing through all of the figure's properties I can't seem to get an where.
And...once I get 4000 to apear instead of .4*10^4 is there a way to rotate the tick mark label so it is not overlapping the other labels.
And..how do you set how many "major" tick marks there are?
Thanks so much!
ME
Try the following:
x=[4000, 8000, 10000, 12000]; % define the x values where you want to have a tick
set(gca,'XTick',x); % Apply the ticks to the current axes
set(gca,'XTickLabel', arrayfun(#(v) sprintf('%d',v), x, 'UniformOutput', false) ); % Define the tick labels based on the user-defined format
Reference: Mathworks
In regards to the label rotation, it seems that Matlab does not support such feature by its own, but someone wrote a script for the label rotation, and you might want to give it a try.
There's a nice function by Yair Altman called ticklabelformat to do that in case you want to still be able to freely play with the axes afterwards
description:
http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/
and the download link:
http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat-set-a-dynamic-format-of-axes-tick-labels