matlab - Matlab subplot linkaxes 未按预期排列轴
问题描述
我似乎无法开始linkaxes
工作(代码如下)。我试图让子图对齐,以便在视觉上 x 轴对于两个子图具有相同的范围和宽度。错位出现在弹出的图形窗口和保存的 JPG 中。使用 Matlab R2018a。
这是我的代码,下图是这个样子:
x1 = [27247 26973 27265 28924 27182 27430 26534 26839 7876 26484 29787 26934 27218 25777 27801 8250 34820 7980 26927 34639];
y1 = [-2350 -3334 -2948 -2336 -2778 -2813 -3383 -3635 -31 -3334 -4216 -3284 -2271 -2477 -2058 375 -821 351 -3441 -1108];
ax1 = subplot(2,1,1);
scatter(x1, y1)
box on
grid on
axis equal
xlims = get(gca, 'XLim')
ax = gca;
ax.XRuler.Exponent = 0;
ax.YRuler.Exponent = 0;
xlims = get(gca, 'XLim')
ax2 = subplot(2,1,2);
scatter(x1, y1)
xlim(xlims)
box on
grid on
ax = gca;
ax.XRuler.Exponent = 0;
linkaxes([ax1,ax2],'x')
我也试过这个(下),但它不会改变情节。
% adding this to the first subplot:
xlims = get(gca, 'XLim')
positioning = get(gca,'position');
% adding this to the second subplot:
xlim(xlims)
set(gca, 'position', [positioning(1) positioning(2)/5 positioning(3) positioning(4)]) %x y width height
解决方案
这已在 Matlab 论坛上解决,这里是该解决方案的摘要/应用:
x1 = [27247 26973 27265 28924 27182 27430 26534 26839 7876 26484 29787 26934 27218 25777 27801 8250 34820 7980 26927 34639];
y1 = [-2350 -3334 -2948 -2336 -2778 -2813 -3383 -3635 -31 -3334 -4216 -3284 -2271 -2477 -2058 375 -821 351 -3441 -1108];
ax1 = subplot(2,1,1);
scatter(x1, y1)
box on
grid on
axis equal
xlims = get(gca, 'XLim')
ax = gca;
ax.XRuler.Exponent = 0;
ax.YRuler.Exponent = 0;
xlims = get(gca, 'XLim')
ax2 = subplot(2,1,2);
scatter(x1, y1)
xlim(xlims)
box on
grid on
ax = gca;
ax.XRuler.Exponent = 0;
set(gcf,'Resize','off') %%%%%%%% this line fixes it for some reason!
linkaxes([ax1,ax2],'x') % want to link x-axis only
%figOut = 'test';
%print(figOut, '-r300', '-djpeg')
推荐阅读
- r - 如何置换给定矩阵的行
- javascript - 是否有类似 Chrome Devtools 的 CSS 属性编辑器小提琴/库?
- html - 如何更改 Ionic react 中 CSS 节点模块的内容?
- reactjs - 从 Material UI 对 TextField 元素进行反应测试
- python - 如何从字符串列表中删除引号和内括号
- nestjs - nestjsx/crud - 如何更改错误响应
- ansible - 在不同的组中重复使用 Ansible Vault 文件
- java - 如何在 JAVA 中默认选择 JTextField?
- amazon-cognito - 将资源服务器添加到 AWS Cognito 用户池会出现错误
- apache-kafka - Kafka-JMX 指标 | BytesInPerSec 的 PromQL 查询