Why does MATLAB export the .png with a graph besides the right y-axis?
18 次查看(过去 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?
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 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!