首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在MATLAB中显示Miller索引?

如何在MATLAB中显示Miller索引?
EN

Stack Overflow用户
提问于 2013-08-03 12:42:26
回答 1查看 1.6K关注 0票数 5

我用MATLAB来绘制XRD分析,其中米勒指数被用来识别晶面方向。这些索引包含3或4个数字,负值显示在该数字的bar上。

在LaTeX中,它可以通过\([1\bar{1}1]\)\([1\overline{1}1]\)命令编写。

为了标记XRD标准的谱线,我使用以下命令:注意,不考虑负值。

代码语言:javascript
复制
std_text_hkl(j)=text(theta{i}(j)-r,0.1,['[' hkl{j} ']'],... % position and label
       of j-th line of i-th standard; hkl{j} holds Miller index in string format
    'parent',ax_std(i),... % association with axes of i-th standard
    'rotation',90,...
    'fontsize',12,...
    'fontname',Font); % Font holds global font setup

如何在不使用'Interpreter','latex'属性的情况下自动在负数上创建条形图,因为我也希望能够更改'FontName'属性。至少我想避免标签和滴答中的不同字体。

编辑:

感谢Magla的评论,我有了这样的想法:

  • 将索引存储为3列矩阵
  • 将标签分隔为5个文本字段
  • 如果Miller索引是负的,则在其上画线(文本框的上线)

实际代码:

代码语言:javascript
复制
rr=get(ax_std(i),'xlim'); % read x-axis limits of i-th standard
    r=(rr(2)-rr(1))/150; % x-offset of Miller indexes
    for j=1:size(dhkl,1)
      theta{i}(j)=asin(lambda/(2*dhkl(j,1)))*360/pi(); %calculating of lines
                   %positions (Bragg's law)
      line('parent',ax_std(i),...
            'xdata',[theta{i}(j) theta{i}(j)],...
            'ydata',[0 dhkl(j,2)],... % j-th line's reflection intensity
            'color',[colors(1+mod(i-1,size(colors,1)),1:3)],...
            'linewidth',3)

%         Miller indexes

      if theta{i}(j)>rr(1)&&theta{i}(j)<rr(2) % test if line is inside axes
          std_text_lbrace(j)=text(theta{i}(j)-r,0.1,'[',...
            'parent',ax_std(i),...
            'verticalalignment','bottom',...
            'horizontalalignment','left',...
            'rotation',90,...
            'fontsize',12,...
            'fontname',Font);
        pos=get(std_text_lbrace(j),'position');
        ext=get(std_text_lbrace(j),'extent');

        std_text_h(j)=text(pos(1),pos(2)+ext(4)/1.5,int2str(abs(hkl(j,1))),...
            'parent',ax_std(i),...
            'verticalalignment','bottom',...
            'horizontalalignment','left',...
            'rotation',90,...
            'fontsize',12,...
            'fontname',Font); % write 1st Miller index
        pos=get(std_text_h(j),'position');
        ext=get(std_text_h(j),'extent')
        if hkl(j,1)<0 % if negative, draw line over it
            wdth=get(ax0,'xlim');
            wdth=wdth(2)-wdth(1);
            set(std_text_h(j),'color','b','edgecolor','g')
            line('parent',ax_std(i),...
                'xdata',[pos(1)-wdth/280*ext(3),pos(1)-wdth/280*ext(3)],...
                'ydata',[pos(2),pos(2)+ext(4)/wdth*100],...
                'color','r')
        end
      end

我不能适应这条线的长度。对于单数来说它太长了,对于两位数字它适合,对于更多的数字(理论上)它太短了。我做错了什么?如何测量旋转文本的'extent'特性?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-06 14:00:47

下面是一段代码,它在负数的顶部显示过行。此解决方案不使用'interpreter','latex',因此可以选择不同的字体。请注意,代码使用了一组单个文本框,每个文本框都有一个\nchar(10)在上线上显示下划线(char(95)' '表示正数字),并在底线上显示相关联的数字。可以选择使用两个不同的文本框来设置下划线与其数字之间的特定距离。但是,这段代码并不适用于所有字体(我可以说,90%的系统字体工作得很好)。

以下代码

代码语言:javascript
复制
%Miller indices
miller_ind = [1 -1 -2 3 -3];

%font definition
c = listfonts;
ind_perm = randperm(length(c));
font_names = {'Arial','Times','Courier New',c{ind_perm}};
font_size = 16;

figure('Color','w','Position',[10 10 600 1000]);
py = 0.05;
for ind_font = 1:12

    %font name
    text(0.03,py,font_names{ind_font},'FontName',font_names{ind_font},'FontSize',font_size);

    %plot miller textbox
    px = 0.6;
    for ii = 1:length(miller_ind)
        if miller_ind(ii)<0
            text(px,py,[char(95) char(10) num2str(-1*miller_ind(ii)) ],...
                'FontName',font_names{ind_font},'FontSize',font_size,'interpreter','none');
        else
            text(px,py,[' ' char(10) num2str(miller_ind(ii)) ],...
                'FontName',font_names{ind_font},'FontSize',font_size,'interpreter','none');
        end
        px = px + 0.03;
    end
    py = py + 0.09;
end

给出这个结果

编辑感谢@Oleg的评论。图片现在直接保存为.tiff,而不是通过.eps保存。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18032994

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档