Question about matlab figure legend.

In summary, the conversation discusses how to save a figure from a MATLAB GUI and the issue of the legend not showing up when using the "copyobj" command. The solution is to recreate the legend using the string used to generate it in the first plot. The conversation also mentions using cell arrays to create a matrix of strings.
  • #1
beanlet
6
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: 630
  • Saved_figure.png
    Saved_figure.png
    38.5 KB · Views: 552
Physics news on Phys.org
  • #2
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:
  • #3
Thank you very much. I just tried to get that axes object, and recreate the legend. It works well. :-)
 
1.

What is a figure legend in MATLAB and how is it different from a regular legend?

A figure legend in MATLAB is a text description or key that explains the symbols, lines, and colors used in a figure. It is different from a regular legend in that it is specific to a particular figure and is usually placed within the figure itself.

2.

How do I add a figure legend in MATLAB?

To add a figure legend in MATLAB, you can use the legend function. This function takes in a cell array of strings as its input, with each string representing a label for a specific line or plot in the figure. You can also specify the location and other properties of the legend using additional parameters.

3.

Can I customize the appearance of the figure legend in MATLAB?

Yes, you can customize the appearance of the figure legend in MATLAB. The legend function allows you to specify the font size, color, and other properties of the legend. You can also use the legend('boxoff') command to remove the box around the legend or use legend('Location','none') to remove the legend altogether.

4.

How can I change the order of the items in my figure legend in MATLAB?

To change the order of items in the figure legend in MATLAB, you can use the flipud function on the cell array of strings representing the legend labels. This will reverse the order of the items in the legend.

5.

Can I have multiple figure legends in a single MATLAB figure?

Yes, it is possible to have multiple figure legends in a single MATLAB figure. You can use the legend function multiple times, each with a different set of labels and properties, to create multiple legends in a single figure.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
805
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
738
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
Back
Top