Why does MATLAB export the .png with a graph besides the right y-axis?
20 views (last 30 days)
Show older comments
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 Comments
Vinayak Choyyan
on 11 Apr 2023
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.
Answers (1)
David Wilkinson
on 22 Apr 2023
Edited: David Wilkinson
on 22 Apr 2023
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 Comments
David Wilkinson
on 26 Apr 2023
Interestingly, I am seeing the issue with just
exportgraphics(gcf,"test.png")
There doesn't seem to be an explainable pattern here...
David Wilkinson
on 26 Apr 2023
This seems to be a recurrent issue. The linked forum states there's no practical workaround (without decreasing resolution).
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!