フィルターのクリア

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 Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by