[英]Matlab - plot; modify X-axis values without modifying graph
我建議更改繪制數據的 x 值,而不是手動更改刻度標簽。 這樣做的好處是您可以放大並正確調整刻度。 通過使用繪圖句柄、讀取XData
屬性並將其寫回所需的修改,可以輕松實現它。 請注意, x
的值保持不變,只有繪圖本身的數據會發生變化。
% example data
y = linspace(-0.6,4.05,100)*1e8;
x = linspace(700,1100,100);
% plot figure
figure; % create a new figure
ph = plot(x,y); % plot and store handle
% change x-values of plot
xp = get(ph,'XData'); % extract from plot using handle
xp = xp/100; % modify x-data
set(ph,'XData',xp); % write back to plot using handle
結果圖:
另一種選擇是手動更改標簽。 這樣做的缺點是原始修改的刻度會保留並且在放大時不會進行調整。因此除非您為繪圖編寫回調函數,否則您不會獲得任何額外的刻度,這比建議的方法更復雜。 不過,這是一種僅更改刻度的方法:
xtick = get(gca,'XTick');
set(gca,'XTick',xtick,'XTickLabel',xtick/100);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.