Why does MATLAB export the .png with a graph besides the right y-axis?
20 ビュー (過去 30 日間)
古いコメントを表示
When opening the exported .png file I see that MATLAB has added or extended the graph beyond the right y-axis. I want to plot several shorter time series of a long temperature history and use xlimit to achieve my wanted time window. When exporting the figure as a svg or eps it is gone but then other information go missing.
How can I eliminate the 'extra' graph on the right side for my .png?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1341319/image.png)
2 件のコメント
Vinayak Choyyan
2023 年 4 月 11 日
Hi Tom,
This is not an expected behaviour. Please share your code and data with us so that we can investigate the issue.
Alternatively, you can create a technical service request at http://www.mathworks.com/support/servicerequests/index.html and send us the above details over the request.
回答 (1 件)
David Wilkinson
2023 年 4 月 22 日
編集済み: David Wilkinson
2023 年 4 月 22 日
Hello,
I just experienced a similar issue using R2023a.
Similar to yourself, I was plotting a figure with a left and right y-axis, using yyaxis left and yyaxis right.
The issue arose when I exported using exportgraphics.
There was a small part of the graph showing outside the main axes, past the right y-axis label.
To remedy this, I did the following:
- Set axis padding to be consistent for both the yyaxis left and yyaxis right plots (I used "axis tight")
- Set the x limit accordingly after the above line, for each plot
yyaxis left
plot(your_data)
axis tight
xlim([0 1])
yyaxis right
plot(your_other_data)
axis tight
xlim([-4 12])
exportgraphics(gcf,"test.png")
I hope this fixes your issue.
All the best,
David
Edit: Whilst I thought this fixed it, it appears having any xlim on a dual y-axis plot causes the issue...
3 件のコメント
David Wilkinson
2023 年 4 月 26 日
Interestingly, I am seeing the issue with just
exportgraphics(gcf,"test.png")
There doesn't seem to be an explainable pattern here...
David Wilkinson
2023 年 4 月 26 日
This seems to be a recurrent issue. The linked forum states there's no practical workaround (without decreasing resolution).
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!