필터 지우기
필터 지우기

Getting unwanted box in the legend

조회 수: 3 (최근 30일)
Captain Rituraj Singh
Captain Rituraj Singh 2024년 2월 28일
댓글: Walter Roberson 2024년 3월 4일
Hi,
I am getting an unwanted box type legend symbol as can be seen in the attached plot. Please help me to get rid-off this thing.
Here is my code for the plotting.
clear all
% Load data for the first data set
infile = 'JGD200z0.0.txt';
data1 = load(infile, '-ascii');
gd1 = data1(:, 1);
pt1 = data1(:, 3);
teff1 = data1(:, 2);
% Load data for the second data set
infile = 'JGD200z0.2.txt';
data2 = load(infile, '-ascii');
gd2 = data2(:, 1);
pt2 = data2(:, 3);
% Load data for the third data set
infile = 'JGD200z0.4.txt';
data3 = load(infile, '-ascii');
gd3 = data3(:, 1);
pt3 = data3(:, 3);
teff3 = data3(:, 2);
% Create a figure
figure;
% Create a 2D surface plot for the first data set
h1 = surf([pt1'; pt1'], [gd1'; gd1'], [teff1'; teff1'], 'EdgeColor', 'interp', 'FaceColor', 'none', 'LineWidth', 3.5, 'LineStyle','--');
hold on;
% Create a 2D surface plot for the second data set
h2 = surf([pt2'; pt2'], [gd2'; gd2'], [teff1'; teff1'], 'EdgeColor', 'interp', 'FaceColor', 'none', 'LineWidth', 3.5, 'LineStyle','-.','marker','o');
% Create a 2D surface plot for the third data set
h3 = surf([pt3'; pt3'], [gd3'; gd3'], [teff3'; teff3'], 'EdgeColor', 'interp', 'FaceColor', 'none', 'LineWidth', 3.5);
% Set the view to have a 2D appearance
view(2);
% Add colorbar
c = colorbar;
ylabel(c, '\bf \fontsize{18}{0}\selectfont $\mathbf T_{eff}$ [GeV]', 'Interpreter', 'latex');
% Set legend
legend([h1, h2, h3], '\zeta = 0.0', '\zeta = 0.2', '\zeta = 0.4');
set(legend, 'FontSize', 25, 'FontWeight', 'bold');
grid on;
title('T = 0.200 GeV','$\mathbf J/\psi$', 'BackgroundColor', [1 1 1], 'LineWidth', 2.5, 'EdgeColor', [0 0 0], 'FontSize', 40, 'Interpreter', 'latex');
ylabel('\bf \fontsize{27}{0}\selectfont $\mathbf \Gamma_{D}$ [GeV]', 'Interpreter', 'latex');
xlabel('\bf \fontsize{27}{0}\selectfont $\mathbf p_{T}$ [GeV]', 'Margin', 4, 'HorizontalAlignment', 'center', 'Interpreter', 'latex', 'VerticalAlignment', 'middle');
ax = gca;
ax.LineWidth = 2.5;
ax.TickLength = [0.02 0.0095];
set(gca, 'XMinorTick', 'on', 'YMinorTick', 'on')

답변 (1개)

Walter Roberson
Walter Roberson 2024년 2월 28일
이동: Walter Roberson 2024년 2월 28일
The boxes in the legend are because you are using surf()
You could create dummy lines,
H(1) = plot(nan, nan, 'LineStyle', '--', 'displayname', '\zeta = 0.0');
H(2) = plot(nan, nan, 'LineStyle', '-.', 'displayname', '\zeta = 0.2');
H(2) = plot(nan, nan, 'LineStyle', '-', 'displayname', '\zeta = 0.4');
legend(H, 'show')
  댓글 수: 3
Walter Roberson
Walter Roberson 2024년 3월 4일
If you replace your current lengend call with
legend(H, 'show')
then you will only legend() the regular (dummy) lines, without the legend showing the boxes,
Walter Roberson
Walter Roberson 2024년 3월 4일
h1 = surf(rand(3,5), rand(3,5), rand(3,5));
hold on
h2 = surf(rand(3,5), rand(3,5), rand(3,5));
h3 = surf(rand(3,5), rand(3,5), rand(3,5));
H(1) = plot(nan, nan, 'LineStyle', '--', 'displayname', '\zeta = 0.0');
H(2) = plot(nan, nan, 'LineStyle', '-.', 'displayname', '\zeta = 0.2');
H(3) = plot(nan, nan, 'LineStyle', '-', 'displayname', '\zeta = 0.4');
legend(H)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by