有没有一种方法可以绘制具有不同(交替)高度的轴值? [英] Is there a way to plot axis values with different (alternating) heights?

查看:66
本文介绍了有没有一种方法可以绘制具有不同(交替)高度的轴值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在MATLAB中绘制经过傅立叶变换的信号. 通过set(gca,'xtick',peaks,'FontSize',12);我可以在x轴上显示峰值. 但有时,峰之间的距离太近,显示峰值的文本与附近的居民合并在一起.我已经在网上搜索过,但可能会问错一个问题:) 所以我的问题是: 如何绘制高度交替变化的峰,如下图所示? 我更喜欢使用1个x轴.

I like to plot in MATLAB a fourier-transformated signal. Via set(gca,'xtick',peaks,'FontSize',12); i can show the peak values at the x-axis. But sometimes, the peaks are too close together and the text showing the peak values is merging together with its neighbours. I have searched the web, but maybe asked the wrong question :) So my question is: How can i plot the peaks with alternating heights, like shown in the picture below? I prefer the use of 1 x-axis.

谢谢您的帮助! :)

推荐答案

+1表示有趣的问题.

+1 for the interesting question.

这是一种做到这一点的方法,也许不是最优雅的方法,但可以说明其逻辑并使其实现:

Here's a way to do that, maybe not the most elegant, but shows the logic and make it happen:

x=0:pi/10:pi;
plot(x,sin(x));

set(gca, 'XTick', x, 'XTickLabel', cell(numel(x),1));
yl=get(gca,'YLim');
for n=1:numel(x)
    if mod(n,2)
       text(x(n), yl(1), {num2str(x(n)),''},'HorizontalAlignment','Center','VerticalAlignment','Top');
    else
       text(x(n), yl(1), {'',num2str(x(n))},'HorizontalAlignment','Center','VerticalAlignment','Top');
    end
end

使用各种文本属性来更改字体大小,或者文字格式等...

Use various text properties to change the font size, or text format etc...

这篇关于有没有一种方法可以绘制具有不同(交替)高度的轴值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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