我总是在XRD图中看到这种图形:
并且我想知道他们是如何做到的?,如果你有不同的XRD图并假设有相同的y轴,matlab可以这样做吗?感谢。
答案 0 :(得分:4)
这是一种方法。您可以根据需要自定义它,但这有望让您前进。
首先创建一个轴并在图中更改其位置/大小,向上移动以为第二个轴腾出空间以及移除您不想要的x和y标签。然后创建具有指定位置/尺寸的第二轴,使其适合第一轴。
示例代码:
clear
clc
%// Generate dummy data
x = 1:2:100;
y1 = rand(1,numel(x));
figure;
%// Make an axes and set its position
haxes1 = axes('Position',[.1 .1 .8 .7],'Color',[1 1 1])
%// Plot 1st curve
plot(x,y1,'Parent',haxes1)
%// Remove box and labels
box off
set(gca,'XTickLabel','','XTick',[],'YTick',[])
hold on
%// Get current axes position. You set it so you could get the parameters
%// directly as well.
axes1Pos = get(gca,'Position');
%// Shift 1st axes upward
set(gca,'Position',[axes1Pos(1) 2.6*axes1Pos(2) axes1Pos(3) axes1Pos(4)])
%// Change the poisition/size of the 2nd axes to fit below the 1st one
haxes2 = axes('Position',[axes1Pos(1) axes1Pos(2)/2.5 axes1Pos(3) axes1Pos(4)/2.5]) ;
%// Use linspace to generate colored points to use with scatter.
c = linspace(1,10,length(x));
%// Add 2nd plot and keep only x label
scatter(x,rand(1,numel(x)),40,c,'filled')
set(gca,'YTick',[])
box off
%// Place a ylabel for both axes
text(-4, 1.7,'Super nice y label','rotation',90,'FontSize',16,'HorizontalAlignment','center')
示例输出:
还有其他方法可以做到这一点。
希望有所帮助!