Figure scaling issues in Linux

10 vues (au cours des 30 derniers jours)
Dimand
Dimand le 10 Août 2024
Commenté : Umar le 10 Août 2024
Getting good DPI settings for the editor in Linux is possible, though a tad annoying.
However, I have no idea how to go about fixing the scaling problems for figures. I can make a temp fix by upping the font size (see image) but can't find a way to fix this. Ideally, want I want is to, by default, scale all images by about 160%.
Font adjusted with
set(findall(gcf,'-property','FontSize'),'FontSize',18)
I could possible go through everything in
get(groot,'factory')
and asjust dozens of settings there to fix this but realy all it needs is a single scale factor that would apply to fonts and data points/lines.
Cheers for any help.

Réponses (1)

Umar
Umar le 10 Août 2024

Hi @Dimand ,

You need a systematic approach to resolve this issue. However, I agree with your approach of achieving a uniform scaling factor for all elements which is considered more efficient.One way to tackle this is by utilizing the set function in MATLAB to adjust properties of graphical objects. In this case, you can set a global scale factor that applies to fonts and other graphical elements. Here's a sample code snippet that demonstrates how you can achieve this:

 % Set the default font size, line width, and scale factor

defaultFontSize = 18;

defaultLineWidth = 1; % Define the default line width

scaleFactor = 1.6; % 160% scaling

% Find all graphical objects and adjust font size and scale

set(findall(gcf,'-property','FontSize'),'FontSize', defaultFontSize * scaleFactor);

set(findall(gcf,'-property','LineWidth'),'LineWidth', defaultLineWidth * scaleFactor);

% Add more properties as needed

% Update the plot to reflect the changes

drawnow;

Using this code snippet will now help you achieve the desired scaling effect across all figures and simplifies the process by avoiding manual adjustments to individual settings.Additionally, keep exploring the groot object in MATLAB which can provide you insights into default settings that can be modified to achieve the desired scaling behavior. However, I will still suggest using a single scale factor approach as demonstrated above which offers a more straightforward and scalable solution. Hope this helps. Please let me know if you still have any further questions.

  4 commentaires
Dimand
Dimand le 10 Août 2024
Thats exactly the issue here though. This is a Linux "problem". I can dual boot to windows with the same machine, same screens and same resolutions/DPI and the displayed Matlab figures from the same script will be scaled completely differently, it's not even usable from one to the other. I can't teach people how to use MATLAB if they can't open something that at least looks close to sensible that they can then adjust to their resolution.
Hence the desire to adjust the default settings/scale to attempt to normalise the outputs on Linux and have some semblance of scale consistency between operating systems.
It sounds like messing with the groot structure on my own machine to best match the more common windows outputs is the only option to achieve that.
Perhaps adding a startup script with a settable scale factor that modifies all relevant groot parameters would be the ideal option.
Umar
Umar le 10 Août 2024
Hi @Dimand,
You are correct in considering modifications to the `groot` structure as a viable solution. By setting global defaults for figure properties, you can achieve a more uniform appearance across platforms. Here’s how you can set up a startup script that allows you to adjust scaling based on your preferences:
% Startup script
scaleFactor = 1.5; % Example scale factor; adjust as necessary
% Modify default properties
groot = groot;
groot.DefaultAxesFontSize = 18 * scaleFactor;
groot.DefaultTextFontSize = 18 * scaleFactor;
groot.DefaultFigurePosition = [100 100 800 600] * scaleFactor; % Adjust figure size
By adjusting these properties, you can create an environment that mimics the Windows output more closely. To further refine your approach, consider dynamically determining the screen resolution and adjusting your scale factor accordingly.
screenSize = get(0, 'ScreenSize');
scaleFactor = min(screenSize(3:4)) / 1080; % Assuming a base resolution of 1080p
This way, your script will adapt based on the actual display characteristics of the machine being used. Now, when it comes to exporting figures, it's crucial to specify a consistent DPI setting, so they look similar regardless of the operating system. Use commands like:
print('MyFigure.png', '-dpng', '-r300'); % Exports at 300 DPI
Again, encourage them to test outputs on their machines and provide feedback regarding figure quality. This collaborative approach can lead to better understanding and help improve your scripts over time. Please let me know if you still have any further questions.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by