![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352280/image.png)
How do I label the scatter colorbar with month and day
37 次查看(过去 30 天)
显示 更早的评论
I wanted to color my scatter plot by date. I was able to do that with the code below but I want to me able to discrimate between dates better than just the month labels. Can I force the colorbar labels to be Month and Date? The code I am using does this fine if I plot the scatter plots by themselves but not as part of another figure. (maybe it is a size issue). This is how I am plotting now (see figures attached):
ax(3) = subplot(2,2,4)
% plot(b_range(k1+3:k2),Bmean3637(k1:k2-3),'.','color','k','markersize',15)
scatter(b_range(k1+3:k2),Bmean3637(k1:k2-3),[],btimestamp(k1+3:k2),'filled')
set(gca,'fontsize',16)
xlabel('Daily pH Range (1 mab)')
ylabel('BEUTI (3-day lag)')
colormap(jet);
h = colorbar; datetick(h,'y','keeplimits');
0 个评论
回答(1 个)
Divija Aleti
2020-8-27
I understand that you want to label the colorbar with month and day, even if it is plotted as a subplot.
Generally, when the size of a figure changes, labels get squeezed as an expected behaviour. Kindly have a look at this possible workaround/solution.
b_range = (8.1-7.75)*rand(82,1)+7.75;
Bmean3637 = 25*rand(82,1)-5;
c=linspace(1,10,82);
ax(3) = subplot(2,2,4);
scatter(b_range,Bmean3637,[],c,'filled')
set(gca,'fontsize',16)
xlabel('Daily pH Range (1 mab)')
ylabel('BEUTI (3-day lag)')
colormap(jet);
labels = {'07/08','07/15','07/22','07/29','08/05','08/12','08/19','08/26','09/02','09/09','09/16','09/23','09/30','10/07'}; %explicitly indicate the labels
h = colorbar('Ticks',1:14,'TickLabels',labels,'limits',[1 14]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352280/image.png)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!