Matlab figure: Keeping same font when opening figure in matlab figure window

11 visualizaciones (últimos 30 días)
I want to use the latex font in a figure or pdf exported from Matlab.
When I create the figure with the attached script in a matlab livescript, in the output it shows the figure on the right. There the font is the right one. Then on the right above the figure in the output there is this button with the arrow "Open in figure window", then the window in the screenshot on the left appears and the font is wrong.
How do I keep the latex font in the figure window and then also if I export to a pdf or svg?
Alternatively as in the end I need to have a pdf of the figure: Can I directly export the diagram to a pdf file with a specific size? I just go the way with the figure window to rescale the diagram without loss of quality. How could I directly export a pdf file of the figure in the size of let's say 15 cm width and 10 cm height?
fontname = 'Latin Modern Roman';
set(0,'DefaultAxesFontName',fontname,'DefaultTextFontName',fontname);
sun = dataset.sun
time = linspace(0,10,length(sun))
fig = plot(time, sun, 'LineWidth',3)
xlabel('Time [d]', 'FontName', 'Latin Modern Roman', 'FontSize', 35);
ylabel('Solar Irridiance [W/m^2]', 'FontName', 'Latin Modern Roman', 'FontSize', 35);
set(gca, 'FontName', 'Latin Modern Roman', 'FontSize', 25);

Respuesta aceptada

Benjamin Kraus
Benjamin Kraus el 24 de Ag. de 2023
The figures within the Live Editor (and figures created by the uifigure command) are using web graphics for rendering, while figures created with the figure command use Java graphics rendering. I suspect what is happening is that the font "Latin Modern Roman" is available for use by the web graphics rendering, but not installed on your system for use by Java graphics. Alternatively, the font "Latin Modern Roman" is not available in either environment, but the font substitution rules are different between the web rendering (which is finding a close enough version to work) vs. Java rendering (which is falling back to a very different font).
Here are a few things to try:
  1. Run the command uisetfont in your command window. Check if "Latin Modern Roman" is listed. If not, you may need to install that font in your system so it can be used by both Java and Web rendering.
  2. Alternatively, after using the button to open the figure in a new figure window, you can use "copyobj" to copy the contents into a new uifigure.
  3. Maybe easier is to just run the code above outside the Live Editor, but specify that it should use a uifigure instead of a regular figure.
sun = dataset.sun
time = linspace(0,10,length(sun))
f = uifigure;
ax = axes(f);
plot(ax, time, sun, 'LineWidth',3)
xlabel(ax,'Time [d]', 'FontName', 'Latin Modern Roman', 'FontSize', 35);
ylabel(ax,'Solar Irridiance [W/m^2]', 'FontName', 'Latin Modern Roman', 'FontSize', 35);
set(ax, 'FontName', 'Latin Modern Roman', 'FontSize', 25);

Más respuestas (0)

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by