如何自定义轮廓线标签? [英] How to customize contour line labels?

查看:106
本文介绍了如何自定义轮廓线标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Octave在等高线图中可视化两个变量的函数,并在其上放置自定义的线标签.

I would like to visualize a function of two variables in a contour plot using Octave, and to put customized line labels on it.

基于Octave文档,我写道:

Building on the Octave documentation, I wrote:

clf;
colormap ("default");
[x, y, z] = peaks ();
subplot(2,1,1);
contour (x, y, z,'showtext', 'on');
title ({"contour() plot, showtext on"; "Z = peaks()"});
subplot(2,1,2);
[ctr, h] = contour (x, y, z);
cll = clabel(ctr, h, 'backgroundcolor',[1 1 1]);
title ({"contour() plot, using clabel()"; "Z = peaks()"});

仅产生少量(如果有的话)不同情节的情节.标签在那里,但看起来一点也不好.我需要这个项目更好的质量.

Which produces two only marginally (if at all) different plots. The labels are there, but don't look nice at all; I need better quality for this project.

我想做的是,按照优先顺序:

What I would like to do is, in order of priority:

  1. 仅显示带有2-3个十进制数字的标签.
  2. 将标签背景更改为白色.
  3. 绘制与轮廓线对齐的标签.

从Octave文档看来,标签值存储在"userdata"中,但是并没有太大帮助,因为:

From Octave documentation it appears that the label values are stored in "userdata", but it's not of much help because:

>> get(cll, "userdata")
ans =
{
  [1,1] =  6.7459
  [2,1] =  5.4167
  [3,1] =  5.4167
  [4,1] =  4.0874
  [5,1] =  4.0874
  [6,1] =  2.7581
  [7,1] =  2.7581
  [8,1] =  2.7581
  [9,1] =  2.7581
  [10,1] =  1.4289
  [11,1] =  1.4289
  [12,1] =  1.4289
  [13,1] =  1.4289
  [14,1] =  0.099636
  [15,1] =  0.099636
  [16,1] =  0.099636
  [17,1] =  0.099636
  [18,1] =  0.099636
  [19,1] =  0.099636
  [20,1] = -1.2296
  [21,1] = -1.2296
  [22,1] = -1.2296
  [23,1] = -1.2296
  [24,1] = -2.5589
  [25,1] = -2.5589
  [26,1] = -2.5589
  [27,1] = -3.8881
  [28,1] = -5.2174

我不确定如何确定一个值的重复次数. 非常感谢您对此事的帮助.

I am not sure how the number of repetitions for a value is determined. I'd appreciate help on this matter.

推荐答案

要显示位数较少的标签,最好的方法是手动指定在哪个z值处绘制轮廓线(请参见文档中的说明="https://octave.sourceforge.io/octave/function/contourc.html" rel ="nofollow noreferrer"> contourc ):

To show labels with fewer digits, the best way is to manually specify at which z-values to draw contour lines (see explanation in the documentation to contourc):

colormap('default');
[x, y, z] = peaks();
vn = ceil(min(z(:))):floor(max(z(:))); % list of all integer values within range of data
contour(x, y, z, vn, 'showtext', 'on');
title({"contour() plot, showtext on"; "Z = peaks()"});

您还可以指定要在其上贴标签的轮廓线:

You can also specify which contour lines to put labels on:

colormap('default');
[x, y, z] = peaks();
vn = ceil(min(z(:))):floor(max(z(:)));
[ctr, h] = contour(x, y, z, vn);
clabel(ctr, h, vn(1:2:end), 'backgroundcolor',[1 1 1]);
title({"contour() plot, showtext on"; "Z = peaks()"});

我这里没有Octave,但是'background color'参数应该起作用.可能是在文本上绘制了线条,而不是在文本上绘制了线条. MATLAB有一个命令uistack来强制绘制顺序,但是在Octave中似乎不存在.在那里,一种可能性可能是更改顺序轴对象的子对象:

I don't have Octave here, but the 'background color' argument should do its thing. It is possible that the lines are drawn over the text, rather than the text over the lines. MATLAB has a command uistack to force drawing order, but this does not seem to exist in Octave. There, one possibility might be to change the order of the children of the axis object:

set(gca,'children',flip(get(gca,'children')))

(注意:MATLAB的contour在选择良好的轮廓线水平方面做得更好,并且默认情况下,它还会中断标签所在的行,因此行和文本不会相交.)

(Note: MATLAB's contour does a better job of picking nice contour levels, and it also by default interrupts the line where the labels are, so lines and text don't intersect.)

这篇关于如何自定义轮廓线标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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