range for xlabel of image (imagesc)
17 views (last 30 days)
Show older comments
I have a problem to show range for xlabel of image (imagesc).
I set my code to plot my data using image or imagesc.
-----------------------------------------------
figure1 = figure;
colormap('jet')
axes1 = axes('Parent',figure1,... 'Layer','top','YDir','reverse',... 'FontWeight','bold',... 'FontSize',12,'FontName','Times New Roman');
box(axes1,'on')
hold(axes1,'on')
xlabel('Time (hh:mm:ss)','FontWeight','bold','FontSize',12,... 'FontName','Times New Roman');
ylabel('Depth (m)','FontWeight','bold','FontSize',12,... 'FontName','Times New Roman');
image(TIME_REF,DEPTH_REF,SPD,'Parent',axes1,'CDataMapping','scaled')
plot(TIME_REF,DEPTH,'k','linewidth',2)
datetick('x','HH:MM:SS')
ylim([0 20])
h = colorbar('eastoutside','FontWeight','bold','FontSize',12,'FontName','Times New Roman');
h.Label.String = 'Velocity (m/s)';
title('Water Velocity','FontWeight','bold','FontSize',14,'FontName','Times New Roman');
-----------------------------------------
x-axis is time using converted serial date number.
When I plot my data, my figure shows like this figure.
I don't want to show the range of no data region like white in the figure.
So, I set the xlim to remove this region as adding xlim([min(TIME_REF) max(TIME_REF)]).
Then, there is another problem like this figure.
This time, no data region is clearly removed.
However, there is no xlabel limiation like xmin and xmax.
How could I solve this problem? I want to show my figure very clearly.
I hope some of you guys can help me.
Thank you.
0 Comments
Answers (2)
Chad Greene
on 21 Apr 2015
It might be easiest to not deal with datetick for this particular issue. Instead, set tick values manually like this:
% one-second intervals from 10:53 to 11:05:
t = datenum(2014,3,15,10,53:1/60:65,0);
x = rand(size(t));
% Plot using datetick:
subplot(211)
plot(t,x)
datetick
% Enter times you want to label here:
labeltimes = {'10:57';'11:01';'11:03'};
% Get datenums of times you want to label:
labeldatenum = datenum(strcat('March 15, 2014, ',labeltimes))
% Plot with manual labels:
subplot(212)
plot(t,x)
axis tight
set(gca,'xtick',labeldatenum,'xticklabel',labeltimes)
Other tips for making your figure more clear:
1. Do not use colormap(jet). The jet colormap is not terribly intuitive for humans to interpret and it puts a weird bright spot arbitrarily about 60% of the way up the scale. The bright spot makes the yellow seem like the most important data. I recommend using the parula colormap if you have a new release of Matlab (or paruly for old releases). Or experiment with Cynthia Brewer's colormaps or brewermap. For data that goes in one direction use a sequential colormap to make it clear that this dataset goes from less to more. For data that diverges (if your velocity scaled from negative values to positive) use a diverging colormap.
2. Place the colorbar horizontally (e.g., with colorbar('location','south')), which will make your plot shorter in height and wider because the human eye likes slightly more landscaped images. This is especially important for time series which we want to see plotting along in time rather than plotted as a simple square.
3. There's an interesting peak in your data. Label that time explicitly.
0 Comments
Cindy Solomon
on 21 Apr 2015
By default the dateticks lie in the middle of the range specified by the tick rather than the beginning of the range. To make datetick labels point to the beginning of the data, it is possible to set the tickmarks to shift and point to the beginning. As I do not have your exact data, an example of doing so would be:
t0=datenum(1998, 6, 4, 12, 0, 0);
t1=datenum(2012, 3, 16, 12, 0, 0);
t=t0:1:t1;
y=2*t;
plot(t, y);
datetick('x');
xt = get(gca, 'XTick');
delta = datenum('01/01/2012') - datenum('01/01/2011');
delta2 = delta/2;
xt = xt - delta2;
set(gca, 'XTick', xt);
For more information on the possible properties of "datetick" that you can change, I recommend looking at the following doc link:
Hope this helps!
0 Comments
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!