Matlab和XTickLabel [英] Matlab and XTickLabel

查看:546
本文介绍了Matlab和XTickLabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让Matlab改变我的轮廓图上的标签大约一个小时.当我去更改XTickLabel或XTick时,它只是完全删除了我的x轴!令人沮丧和令人发指的是,我正在精确地做所有帮助页面

I've been trying to get Matlab to change the labelling on my contourf plots for about an hour now. When I go to change XTickLabel or XTick, it simply removes my x-axis altogether! The frustrating and infuriating thing is that I'm doing exactly what all the help pages and help forums are asking me to do - I honestly don't understand why this is not working.

因此,我在这里.

我的绘图代码(不需要知识的功能-代码非常丰富.但是,它是具有有效数据和范围的2D轮廓图-轴是问题,而不是图形):

My plotting code (knowledge of the function shouldn't be required - the code is rather intense. It is, however, a 2D contourf plot with valid data and ranges - the axes are the issue, not the graph):

   contourf(time,f,power,levels)
   colormap(jet(levels))
   set(gca,'XTickLabelMode','manual')
   set(gca, 'XTick', 0:23);
   set(gca, 'XTickLabel', {'0';'1';'23'});
   xlabel('Time (UT)')
   ylabel('Frequency (Hz)')
   caxis([0,8])
   axis([0 StopTime 0 0.1])

任何帮助将不胜感激!

推荐答案

已解决:

我意识到'XTick'依赖于我用来定义x轴的数组的当前值.我不能仅仅假设matlab将平均分配一个新数组(至少,如果有办法做到这一点,我不知道).因此,由于我在X轴上有85,680个数据点,因此可以通过以下方式重新缩放它:

I realized that the 'XTick' relied on current values of the array I was using to define the x-axis. I can't just assume matlab will evenly space a new array (at least, if there's a way to do that, I don't know). So, since I have 85,680 data points on my X-axis, I simply rescaled it by:

   set(gca, 'XTick', 0:3570:85680)
   set(gca, 'XTickLabel', num2cell(0:24))

故事的寓意:Matlab不允许您使用这两个功能将新的轴随意粘贴在旧的轴上.

Moral of the story: Matlab doesn't let you arbitrarily stick a new axis over an old one using these two functions.

这篇关于Matlab和XTickLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆