フィルターのクリア

Why does my plot line appear outside the axes?

22 ビュー (過去 30 日間)
Jamie Bragg
Jamie Bragg 2024 年 4 月 26 日
コメント済み: Sam Chak 2024 年 5 月 6 日
I'm trying to make a double y-axis plot of data that extends beyond the x-axis limits of the plot. When I save the plot as a .png, the plot lines appear outside the right axis of the plot.
Here's code for a simplified version of what I'm trying that produces the issue:
x = [0 1 2 3 4];
yl = [0 1 2 4 3];
yr = [0 2 3 1 2];
yyaxis left
plot(x, yl)
yyaxis right
plot(x, yr)
xlim([1 3])
saveas(gcf,'[PATH].png')
And here's the image that's saved:
I know that there's a workaround of shortening the data arrays to the range of the x-axis limits before plotting, but I was wondering if there's a more elegant solution.
  8 件のコメント
Jamie Bragg
Jamie Bragg 2024 年 4 月 29 日
@Adam Danz I was originally using MATLAB desktop, which is where the bug occurs. When I run the code you suggest, I get:
r =
struct with fields:
GraphicsRenderer: 'OpenGL Hardware'
Vendor: 'Intel'
Version: '4.5.0 - Build 31.0.101.4953'
RendererDevice: 'Intel(R) Iris(R) Xe Graphics'
Details: [1×1 struct]
ans =
struct with fields:
RendererDriverVersion: '31.0.101.4953'
RendererDriverReleaseDate: '2023-11-7'
HardwareSupportLevel: 'Full'
SupportsDepthPeelTransparency: 1
SupportsAlignVertexCenters: 1
SupportsGraphicsSmoothing: 1
MaxTextureSize: 16384
MaxFrameBufferSize: 16384
When using MATLAB online (Firefox), the saved PNG image doesn't have the issue. I get the same information as Sam Chak when running the commands you suggest.
Adam Danz
Adam Danz 2024 年 5 月 2 日
@Sam Chak and @Jamie Bragg thanks for sharing this renderer information. It shows exactly what I needed to see. I'll take it from here and add this bug to our tracker. Thanks again for your help and cooperation!

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2024 年 5 月 6 日
編集済み: Adam Danz 2024 年 5 月 6 日
This appears to be a bug specific to the OpenGL renderer. Thanks for reporting this issue. Investigation will continue internally.

その他の回答 (1 件)

Sam Chak
Sam Chak 2024 年 4 月 26 日
Because the xlim() command is used on the right y-axis plot.
x = [0 1 2 3 4];
yl = [0 1 2 4 3];
yr = [0 2 3 1 2];
yyaxis left
plot(x, yl), xlim([1 3])
yyaxis right
plot(x, yr), xlim([1 3])
% saveas(gcf,'[PATH].png')
  5 件のコメント
Sam Chak
Sam Chak 2024 年 4 月 26 日
@Jamie Bragg, If the image is displayed correctly in MATLAB, what happens when you save the figure again after it has been properly rendered?
Jamie Bragg
Jamie Bragg 2024 年 4 月 26 日
I saved the figure manually from the figure MATLAB figure window after it rendered, and looks fine!
But if I run the command to save it after it's rendered, it still has the clipping issue.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by