The legend overlay is displayed when drawing
Show older comments

14 Comments
dpb
on 29 Aug 2024
Attach a minimum working example that illustrates the problem; we can't fix what we don't know how was done...it doesn't do that as a general rule.
Mathieu NOE
on 29 Aug 2024
Pls post a working code - no one can work on just an image
It seems to work with some test data.
N = 50;
x = sort(rand(1,N));
y = rand(1,N);
z = rand(1,N);
x_interp = linspace(0,1,N);
y_interp = interp1(x, y, x_interp);
z_interp = interp1(x, z, x_interp);
z_real = z_interp + randn(1,N);
figure
h1 = plot3(x, y, z, 'o', 'MarkerSize', 6, 'MarkerFaceColor', 'r');
hold on;
plot3(x_interp, y_interp, z_interp, 'b-', 'LineWidth', 2);
plot3(x_interp, y_interp, z_real, 'g-', 'LineWidth', 2);
grid on;
set(gca, 'YDir', 'reverse');
xlabel('X');ylabel('Y');zlabel('Z');
title('隧道反演结果三维示意图');
legend( '隧道中心反演结果', '反演的隧道三维分布', '模拟的隧道三维分布');
xlim([0 200]);
ylim([0 200]);
zlim([-25 0]);
hold off;
龙
on 30 Aug 2024
Walter Roberson
on 30 Aug 2024
Your example code does not use the patch() function ?
龙
on 30 Aug 2024
Walter Roberson
on 30 Aug 2024
Please post a working example.
龙
on 30 Aug 2024
p1 = patch(x, y, z, 'FaceColor', 'blue');
legend([h1, p1], {'反演结果', '填充'});
That is not a working example...most particularly, h1 is undefined when get there and that's probably the key ingredient here.
Submit code and format it with the "CODE" button, then use the "RUN" button -- when your result shows the issue, then you'll have a working example. Easiest route would likely be to pare down your real use case to the barest of lines that you can that show up the problem on your local machine first, then paste that in...
Looks okay in my test.
N = 50;
x = sort(rand(1,N));
y = rand(1,N);
z = rand(1,N);
x_interp = linspace(0,1,N);
y_interp = interp1(x, y, x_interp);
z_interp = interp1(x, z, x_interp);
z_real = z_interp + randn(1,N);
figure
h1 = plot3(x, y, z, 'o', 'MarkerSize', 6, 'MarkerFaceColor', 'r');
hold on;
plot3(x_interp, y_interp, z_interp, 'b-', 'LineWidth', 2);
plot3(x_interp, y_interp, z_real, 'g-', 'LineWidth', 2);
grid on;
set(gca, 'YDir', 'reverse');
xlabel('X');ylabel('Y');zlabel('Z');
title('隧道反演结果三维示意图');
p1 = patch(x, y, z, 'FaceColor', 'blue');
legend([h1, p1], {'反演结果', '填充'});
xlim([0 200]);
ylim([0 200]);
zlim([-25 0]);
hold off;
dpb
on 30 Aug 2024
"I used patch() in other scripts, and the legend in the drawing kept showing errors afterwards"
If the use of scripts in the above means what a script means in MATLAB, then you quite possibly have invalid handles hanging around since scripts run in the command workspace.
Execute
clear all % save hard to regenerated data first
and then retry the script and see if the problem doesn't go away.
If so, then encapsulate your scripts as functions so you don't leave temporary variables hanging around.
If not, you will at least have generated a test case that should demonstrate the problem that others can try.
If not, also then close and restart Matlab (be sure to save anything of value including the updated script/function files first) and try again.
If it then still repeats, it may be time to reinstall or check for updates.
OK, that's interesting and informative. This leads to confriming the fact something is unique/different on the particular machine; now it's down to specifics that may matter. Which OS, release, is it updated? Same with MATLAB although with a reinstall if you downloaded afresh it should include updates but you didn't say which release with the question posting(*).
These kinds of graphical display issues often get into the specifics of the display hardware/chipset and drivers and the MATLAB renderer. Updating your graphics drivers from the chipset/card vendor can sometimes fix things.
However, first work through the suggestions at <resolving low level graphics issues> and you may be able to resolve it yourself. If switching to a software OpenGL renderer makes the issue go away, then it is pretty clearly something in the hardware/drivers.
(*) There's an alternative thing one could try albeit time-consuming; download a prior release and see if the symptom stays/goes away...one can have multiple releases of MATLAB installed at the same time so don't have to remove your current install; you just need patience and enough bandwidth it's not too much of a chore.
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!



