gpt4 book ai didi

matlab - 是否可以用科学计数法标记等高线图?

转载 作者:太空宇宙 更新时间:2023-11-03 20:15:30 26 4
gpt4 key购买 nike

考虑以下 MWE 来创建等高线图:

close all
[X,Y]=meshgrid(0:100,0:100);
Z=(X+Y.^2)*1e10;
[C,h]=contour(X,Y,Z);
h.ShowText='on';

但是,标签始终显示轮廓的完整整数符号。 是否有合理的方法来改变这种行为?(例如,类似于 MATLAB 在命令窗口中显示变量的方式,或强制的科学记数法)

enter image description here

最佳答案

您可以使用未记录的 MarkedClean 事件来执行此操作。

不幸的是,Matlab 会在每次重新绘制绘图(例如调整图形大小)时更新文本 - 因此您需要添加一个监听器以在每次发生时更新它们 - 因此您为什么要监听此特定事件。

function test
figure
[X,Y]=meshgrid(0:100,0:100);
Z=(X+Y.^2)*1e10;
[C,h]=contour(X,Y,Z);
h.ShowText='on';
% add a listener and call your new format function
addlistener(h,'MarkedClean',@(a,b)ReFormatText(a))
end
function ReFormatText(h)
% get all the text items from the contour
t = get(h,'TextPrims');
for ii=1:length(t)
% get the current value (Matlab changes this back when it
% redraws the plot)
v = str2double(get(t(ii),'String'));
% Update with the format you want - scientific for example
set(t(ii),'String',sprintf('%0.3e',v));
end
end

关于matlab - 是否可以用科学计数法标记等高线图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40883842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com