Issue with Incorrect Graphs Displayed in MATLAB on Linux Mint 22incorrect graph outputs

5 views (last 30 days)
Hi everyone,
I’ve encountered an issue where the graphs plotted in MATLAB on my system appear incorrect, both in the desktop version and MATLAB Online. However, when I export these graphs to a PDF, the output is correct. I tested the same code on a different machine, and the graphs were displayed correctly without any issues.
Here are some details about my setup:
  • Operating System: Linux Mint 22
  • MATLAB version: [Include your MATLAB version here]
  • The problem occurs in both desktop MATLAB and MATLAB Online.
  • Exported graphs (e.g., to PDF) show the correct output.
I suspect the issue could be related to my laptop or some specific settings, but I’m not sure where to start. Has anyone experienced a similar issue or have suggestions on how to resolve this?
Thank you in advance for your help!
  3 Comments
Bilawal
Bilawal on 19 Jan 2025
Edited: Bilawal on 19 Jan 2025
I have attachd the code below, here the code runs fine, even when i export it to pdf it runs fine, but I have attached an image of how the graph appears to me on the matlab desktop
here s the matlab version that I have
MATLAB Version: 24.2.0.2806996 (R2024b) Update 3
-----------------------------------------------------------------------------------------------------------
MATLAB Version 24.2 (R2024b)
Simulink Version 24.2 (R2024b)
Image Acquisition Toolbox Version 24.2 (R2024b)
Image Processing Toolbox Version 24.2 (R2024b)
MATLAB Coder Version 24.2 (R2024b)
MATLAB Compiler Version 24.2 (R2024b)
Signal Processing Toolbox Version 24.2 (R2024b)
Symbolic Math Toolbox Version 24.2 (R2024b)
clc; clear; close all
A = 1; J = 50; M = 10; L = 20000; PSD = 0;
T = 1; Ts = T / M; fs = 1 / Ts;
% Loop over L realizations
for jj = 1:L
sNt = [];
Bits = (sign(randn(1, 2*J+1)) + 1) / 2; % Generate random bits (0 or 1)
% Generate Bipolar-NRZ signal for each bit
for ii = 1:2*J+1
if Bits(ii) == 1
sNt = [A*ones(1, M), sNt]; % 1 -> positive signal for the whole symbol period
else
sNt = [-A*ones(1, M), sNt]; % 0 -> negative signal for the whole symbol period
end
end
% Calculate the PSD
PSD = PSD + abs(fft(sNt)).^2;
end
% Normalize PSD
PSD = PSD / L / (2*J+1) / T;
LPSD = length(PSD);
% Plot PSD (Unnormalized) vs. index k
figure(1);
plot(PSD, 'k-', 'linewidth', 1.5);
set(gca, 'FontSize', 14); axis tight; grid on;
xlabel('$0 \le k \le (2J+1)M$', 'FontSize', 16, 'interpreter', 'latex');
title('PSD (Unnormalized) vs. index $k$', 'FontSize', 14, 'interpreter', 'latex');
ylabel('$\Psi_x[k]$', 'FontSize', 16, 'interpreter', 'latex');
h = text(400, 50, ['$J = ' num2str(J) ', M = ' num2str(M) '$']);
set(h, 'fontsize', 14, 'interpreter', 'latex')
drawnow;
% DTFT frequency axis
DTFT_xaxis = linspace(0, 2*pi, LPSD);
figure(2);
plot(DTFT_xaxis, PSD, 'k-', 'linewidth', 1.5);
set(gca, 'FontSize', 14); axis tight; grid on;
xlabel('$0 \le \Omega \le 2\pi$ [radian]', 'FontSize', 16, 'interpreter', 'latex');
title('PSD (Unnormalized) vs. $\Omega$', 'FontSize', 14, 'interpreter', 'latex');
ylabel('$\Psi_x(\Omega)$', 'FontSize', 16, 'interpreter', 'latex');
drawnow;
% Normalized frequency axis for CTFT
fT = linspace(-T*fs/2, T*fs/2, LPSD); % Normalized frequency axis
% Normalize PSD for CTFT
Area = sum(PSD) * (fT(2) - fT(1));
CTFT_PSD = PSD / Area;
CTFT_PSD = [fliplr(CTFT_PSD(end:-1:floor(LPSD/2))) CTFT_PSD(1:floor(LPSD/2)-1)];
% Plot normalized two-sided PSD
figure(3);
plot(fT, CTFT_PSD, 'k-', 'linewidth', 1.5);
set(gca, 'FontSize', 14); axis tight; grid on;
xlabel('$-Tf_s\,/\,2 \le Tf\le Tf_s\,/\,2$', 'FontSize', 16, 'interpreter', 'latex');
ylabel('$\Psi_x(f)$', 'FontSize', 16, 'interpreter', 'latex');
xlim([-fs/2 fs/2]);
title('PSD vs. $Tf$ [Normalized and two-sided]', 'FontSize', 14, 'interpreter', 'latex');
drawnow;
% Log-scale PSD plot
semilogy(fT, CTFT_PSD, 'k-', 'linewidth', 1.5);
set(gca, 'FontSize', 14);
xlabel('$-Tf_s\,/\,2 \le Tf\le Tf_s\,/\,2$', 'FontSize', 16, 'interpreter', 'latex');
ylabel('$\Psi_x(f)$ [dB]', 'FontSize', 16, 'interpreter', 'latex');
ylim([1e-3 1]);
xlim(T * [-fs/2 fs/2]);
title('Log PSD vs. $Tf$ [Normalized and two-sided]', 'FontSize', 14, 'interpreter', 'latex');
grid on; axis tight; drawnow;
Satwik
Satwik on 22 Jan 2025
Hi Bilawal,
I suspect this is a low-level graphics rendering issue pottentially caused due to old graphics hardware or outdated graphics drivers.
Please refer to the existing MATLAB answer post for workarounds to resolve the issue:

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Performance 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!