Axis exponent missing when using exportgraphics to export figure in pdf vector format (or image)

Hi,
When I use exportgraphics to export a figure in pdf vector graphics format (or even image formats such as .png, .tiff), any axis exponents from the figure are missing in the output export file. For my application, I need to export the figure in vector format.
Example code to generate figure:
fig1 = figure(1);
plot(rand(10,1)*10^-5)
exportgraphics(fig1,'testMissingAxisExponent01.pdf','ContentType','vector');
Example figure exported by using 'Save As' in MATLAB figure GUI (which properly shows the axis exponent):
Example figure generated from exportgraphics (with the missing axis exponent):
I first discovered this issue when working with plots in nested tiles using tiledlayouts and tried increasing the padding with no success. However, this issue seems to be related to exportgraphics.
Any solutions or workarounds? Thank you!

2 件のコメント

Same issue here......
I was using the export button from the axes toolbar instead of calling exportgraphics programmatically, but I encounter the same problem with the exponent for the y-axis being cut off when I try to save a plot. I'm using MATLAB R2024a.
After I found this question on the MATLAB Answers web page, I took a look at the documentation for the exportgraphics command. The "Padding" option seemed promising as a potential solution, but when I tried that I got an error message stating, "Illegal option 'padding' given." What I tried, specifically, was to click on the plot axes to select my plot. Then, in the command window:
ax = gca;
exportgraphics(ax, "figurepadding.png", "Padding", "figure")

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

 採用された回答

Adam Danz
Adam Danz 2024 年 6 月 3 日
編集済み: Adam Danz 2024 年 6 月 14 日
This issue has been fixed in MATLAB R2024a Update 4.
=================================================
Thanks for reporting this issue. Follow progress on this bug by following the bug report below
The recommended work-around is to call the print function. For example, to export the current figure to a PNG file named myplot.png, use this command:
print("myplot.png","-dpng")
To copy the current figure to the clipboard as pixels, use this command:
print("-clipboard","-dbitmap")

7 件のコメント

MP
MP 2024 年 6 月 17 日
Hi @Adam Danz - Is Update 4 released to the public? I'm using Update 3 and keep checking for Update 4 but my Matlab says it is up-to-date and doesn't give me the option to download Update 4.
Adam Danz
Adam Danz 2024 年 6 月 17 日
Try manually checking for updates. Those instructions are toward the top if this link:
I have the same issue as @MP. I tried manually checking for updates to go from from MATLAB R2024a Update 3 to Update 4, but there is currently no update available.
Appreciate your help with this issue @Adam Danz!
Adam Danz
Adam Danz 2024 年 6 月 18 日
Make sure the Software Maintenance Service on your license is current
Check your licenses here
If you continue to have trouble, please contact tech support.
I wish I could help more but I'm just a developer in graphics and charting without much experience in licensing and release issues.
I asked some of the staff members who work on update releases to check whether release R2024a Update 4 should be available. Based on what those staff members said I expect it should be available now. Can you try checking for updates again to see if Update 4 is available on your machine?
I just checked again and the R2024a Update 4 is now available. I was able to install the new update.
I can confirm that the issues with exportgraphics and copygraphics functions excluding secondary axes labels (including axes exponents) have been resolved.
Thanks to the community for your input and the staff for fixing the issue!
Adam Danz
Adam Danz 2024 年 6 月 21 日
Thanks for sharing that confirmation, @Raymond Yeung.

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

その他の回答 (1 件)

Pablo Nicolas
Pablo Nicolas 2024 年 3 月 27 日
移動済み: Fangjun Jiang 2024 年 3 月 27 日
I encountered the same problem and I was looking for an answer or possible solution but unsucessfully. What I did that finally solved the issue was to install an older Matlab version (Matlab 2023a). Hopefully, this was helphul for you!

2 件のコメント

Raymond Yeung
Raymond Yeung 2024 年 3 月 27 日
移動済み: Fangjun Jiang 2024 年 3 月 27 日
Thanks Pablo! I tried exporting my plots using "exportgraphics" again in older versions of MATLAB (R2023a, R2023b) which indeed does work. I put in a bug report for this issue in MATLAB R2024a.
From user discussions (Pablo Nicolas) and interactions with MathWorks Support, this is an issue that appeared with MATLAB R2024a. I have already put in a bug report.
Current workarounds include using an older version of MATLAB (tested MATLAB R2023a and R023b with success). Alternatively, you could use "saveas" instead of "exportgraphics". However, if you want to export in vector format, you would have to change the figure renderer to 'Painters' which will apparently be removed in future releases.
fig1.Renderer = 'painters';
saveas(fig1,'testPlotSaveAs.pdf')
If you still want to use "exportgraphics" in MATLAB R2024a, another workaround is to use the "text" function to superimpose the exponent onto the plot, but this workaround is not ideal since it is tricky to ensure you get the correct position on the plot.
fig1 = figure(1);
plot(rand(10,1)*10^-5);
ylimits = ylim;
exponent = floor(log10(ylimits(2)));
% Create a string that represents the exponent part
exponentStr = ['x10^{' num2str(floor(log10(ylimits(2)))) '}'];
% Add text to the plot to display the exponent
text(0, 1.03, exponentStr, 'Units', 'normalized', 'FontSize', 10);
% Manually adjust y-axis tick labels to not include the exponent part
% This step is primarily so that the non-exported figure does not have
% overlapping exponent text
yticks = get(gca, 'YTick');
newYTickLabels = arrayfun(@(y) num2str(y/10^exponent), yticks, 'UniformOutput', false);
set(gca, 'YTickLabel', newYTickLabels);
exportgraphics(fig1,'addTextToPlot.pdf','ContentType','vector');

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

カテゴリ

ヘルプ センター および File ExchangePrinting and Saving についてさらに検索

製品

リリース

R2024a

質問済み:

2024 年 3 月 24 日

コメント済み:

2024 年 6 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by