MATLAB Question about matlab figure legend.

  • Thread starter Thread starter beanlet
  • Start date Start date
  • Tags Tags
    Figure Matlab
Click For Summary
SUMMARY

The discussion focuses on saving a figure with a legend in MATLAB when the plot is a child of a uipanel. The user encountered an issue where the legend did not appear after using the "copyobj" command to duplicate the uipanel. It was clarified that the legend does not have a "Parent" property, and the solution involves recreating the legend using the original legend string or a cell array of strings. The user successfully resolved the issue by obtaining the axes object and recreating the legend.

PREREQUISITES
  • Familiarity with MATLAB GUI components, specifically uipanels.
  • Understanding of the "copyobj" command in MATLAB.
  • Knowledge of MATLAB cell arrays and how to create them.
  • Basic understanding of MATLAB plotting functions and legend creation.
NEXT STEPS
  • Learn how to use the "copyobj" command effectively in MATLAB.
  • Explore the MATLAB documentation on cell arrays for advanced data handling.
  • Research methods for managing graphical objects in MATLAB GUIs.
  • Investigate best practices for creating and managing legends in MATLAB plots.
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those working with GUI components, data visualization, and anyone needing to manage plot legends effectively.

beanlet
Messages
6
Reaction score
0
Hey folks,

I need to save a figure from my MATLAB GUI, which is just a simple plots. Because this plot is the child of a uipanel, so I just use "copyobj" command to copy the handle of the uipanel to the new figure. However, although everything is copied, the legend is not really showing up. I am confused and do not know how to do the setting.

legend does not have the "Parent" property, so I cannot just do the same setting as the other graphical objects in the plots. Can anyone give me any suggestions on this? Thanks a lot. :-)

I attached my screen shots here, and you can see the legend is gone...
 

Attachments

  • GUI.png
    GUI.png
    40.7 KB · Views: 702
  • Saved_figure.png
    Saved_figure.png
    38.5 KB · Views: 616
Physics news on Phys.org
In this matter, MATLABdude is a MATLABdud.

http://simpsons.wikia.com/wiki/Disco_Stu

EDIT: Legend doesn't have a handle. However, if you pass the string used to generate the first legend in the first plot, you can just recreate it in the second. You probably know this, but you can also make a matrix of strings (a cell array) using the {} braces. For instance:

>> bowlTeam = {'Fred', 'Tammy', 'Joe'};

Using bowlTeam{3} returns Joe. I believe bowlTeam(3) returns either an e, or is a syntax error. Mathworks documentation page on cell arrays:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04bw6-98.html
 
Last edited:
Thank you very much. I just tried to get that axes object, and recreate the legend. It works well. :-)
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K