57933

how to change the sequence of the legend

I want to change the sequence of the legend.

See the figure. I want the sequence to be: green and data2, blue and data3, black and data4, red and data1.

Could anyone give a demo?

<img src="https://i.stack.imgur.com/hPvrh.png" alt="enter image description here">

Answer1:

Change the order in which the plots are added to the figure, and then call legend normally. That should do it.

<hr>

You can also do it as follows. First get handles to the individual plots:

h1 = plot(1:5); hold on h2 = plot(11:15, 'r');

Then call legend specifying the order:

legend([h1 h2],'plot1','plot2')

or

legend([h2 h1],'plot2','plot1')

<img src="https://i.stack.imgur.com/FUGiK.png" alt="enter image description here">

<img src="https://i.stack.imgur.com/z69O3.png" alt="enter image description here">

Answer2:

In case, you have already made the plots or if you added some plot at the end, which want to reorder to somewhere in middle, you can try this way:

1) Go to show Plot Tools and Dock Figure.

2) Delete the data (which you want to move to bottom). Then undo delete.

3) Refresh legend.

Recommend

  • How can I prevent a double submit($.post) with jQuery
  • How to make sure my plots share same axis while using multiplot in gnuplot?
  • Javascript - variable scope in event handler
  • Python Multiple file writing question
  • Interpret strings as packed binary data in C++
  • Force ggplot legend to show all categories when no values are present [duplicate]
  • Maple: How to insert a command to force my code to choose random integer values to find my values?
  • Add Jpanel to Jframe NetBeans
  • How to convert Neo4j Result to GraphJSON
  • Insert records into two table at once
  • Recursion in ASP.NET Core Razor views
  • mapping between two ontologies
  • Jquery resizable reposition handle after scroll
  • Is there a way to link a linux's thread TID and a pthread_t “thread ID”
  • 'doc_del_count' bigger than 'doc_count' on CouchDB
  • Cannot invoke my method on the array type int[]
  • Lua: Line breaks in strings
  • Angular Bootstrap Carousel Slide Transition not working correctly
  • Iron Router: How do I send data to the layout?
  • How to define and use opencv mat of user type
  • Breeze - Deleted Items nav properties bug
  • Linq Objects Group By & Sum
  • Optimizing database types to compact database (SQLite)
  • javaw.exe and eclipse startup problems
  • Cassandra Data Model
  • How do you troubleshoot character encoding problems?
  • Calling of Constructors in a Java
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Buffer size for converting unsigned long to string
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • need help with bizarre java.net.HttpURLConnection behavior
  • How does Linux kernel interrupt the application?
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory
  • Python/Django TangoWithDjango Models and Databases
  • Why do underscore prefixed variables exist?