两个图的Matlab图例仅适用于第二个图

时间:2016-06-23 17:44:13

标签: matlab matlab-figure

我需要绘制两个矢量的数据,并希望每个矢量的数据点以图例中说明的不同颜色显示。但是,下面的代码仅显示第二个代码。我做错了什么?

Shah Rukh Khan
http://forbesindia.com/media/list/SRK_2015_SM.jpg
Salman Khan
http://forbesindia.com/media/list/salman_new_SM.jpg
Amitabh Bachchan
http://forbesindia.com/media/list/Amitabh_SM.jpg
Mahendra Singh Dhoni
http://forbesindia.com/media/list/Dhoni_SM.jpg
Aamir Khan
http://forbesindia.com/media/list/Amir_Sm.jpg
Akshay Kumar
http://forbesindia.com/media/list/Akshay_SM.jpg
Virat Kohli
http://forbesindia.com/media/list/009_SM.jpg
Sachin Tendulkar
http://forbesindia.com/media/list/006_SM.jpg
Deepika Padukone
http://forbesindia.com/media/list/Deepika_SM.jpg
Hrithik Roshan
http://forbesindia.com/media/list/Hrithik_SM.jpg
Ranbir Kapoor
http://forbesindia.com/media/list/Ranbir_Sm.jpg
Rohit Sharma
http://forbesindia.com/media/list/024_SM.jpg
Priyanka Chopra
http://forbesindia.com/media/list/014_SM.jpg
AR Rahman
http://forbesindia.com/media/list/020_SM.jpg
Shahid Kapoor
http://forbesindia.com/media/list/034_SM.jpg
Shikhar Dhawan
http://forbesindia.com/media/list/Shikhar_SM.jpg
Kareena Kapoor Khan
http://forbesindia.com/media/list/007_SM.jpg
Katrina Kaif
http://forbesindia.com/media/list/Katrina_SM.jpg
Anushka Sharma
http://forbesindia.com/media/list/036_SM.jpg
Suresh Raina
http://forbesindia.com/media/list/030_SM.jpg
Yuvraj Singh
http://forbesindia.com/media/list/017_SM.jpg
Sonakshi Sinha
http://forbesindia.com/media/list/041_SM.jpg
Madhuri Dixit
http://forbesindia.com/media/list/038_SM.jpg
Ajay Devgn
http://forbesindia.com/media/list/019_SM.jpg
Ajinkya Rahane
http://forbesindia.com/media/list/Ajinkya Rahane_SM.jpg
Sonam Kapoor
http://forbesindia.com/media/list/048_SM.jpg
Kapil Sharma
http://forbesindia.com/media/list/Kapil Sharma_SM.jpg
Saif Ali Khan
http://forbesindia.com/media/list/015_SM.jpg
Yo Yo Honey Singh
http://forbesindia.com/media/list/Honey_SM.jpg
Ranveer Singh
http://forbesindia.com/media/list/Ranvir_SM.jpg
Ravichandran Ashwin
http://forbesindia.com/media/list/Ravichandra_Ashwin_SM.jpg
Sonu Nigam
http://forbesindia.com/media/list/047_SM.jpg
Shreya Ghoshal
http://forbesindia.com/media/list/042_SM.jpg
Aishwarya Rai Bachchan
http://forbesindia.com/media/list/045_SM.jpg
Virender Sehwag
http://forbesindia.com/media/list/008_SM.jpg
Mahesh Babu
http://forbesindia.com/media/list/031_SM.jpg
Dhanush
http://forbesindia.com/media/list/Dhanush_SM.jpg
Sania Mirza
http://forbesindia.com/media/list/Sania Mirza_SM.jpg
Saina Nehwal
http://forbesindia.com/media/list/029_SM.jpg
Alia Bhatt
http://forbesindia.com/media/list/Alia Bhatt_SM.jpg
Ravindra Jadeja
http://forbesindia.com/media/list/Ravindra_Jadeja_SM.jpg
Allu Arjun
http://forbesindia.com/media/list/Allu Arjun_SM.jpg
Parineeti Chopra
http://forbesindia.com/media/list/Parineeti Chopra_SM.jpg
Karan Johar
http://forbesindia.com/media/list/037_SM.jpg
Sunny Leone
http://forbesindia.com/media/list/071_SM.jpg
Kamal Haasan
http://forbesindia.com/media/list/Kamal Hassan_SM.jpg
Jacqueline Fernandez
http://forbesindia.com/media/list/Jacqueline Fernandez_SM.jpg
Ishant Sharma
http://forbesindia.com/media/list/IshantSharma_SM.jpg
Harbhajan Singh
http://forbesindia.com/media/list/023_SM.jpg
Gautam Gambhir
http://forbesindia.com/media/list/013_SM.jpg
Farhan Akhtar
http://forbesindia.com/media/list/039_SM.jpg
N.Santhanam
http://forbesindia.com/media/list/celeb_2015_sm.jpg
John Abraham
http://forbesindia.com/media/list/021_SM.jpg
Varun Dhawan
http://forbesindia.com/media/list/Varun Dhawan_SM.jpg
Arjun Kapoor
http://forbesindia.com/media/list/Arjun Kapoor_SM.jpg
Kangana Ranaut
http://forbesindia.com/media/list/077_SM.jpg
Shraddha Kapoor
http://forbesindia.com/media/list/Shraddha Kapoor_SM.jpg
Kajal Aggarwal
http://forbesindia.com/media/list/Kajal Aggarwal_SM.jpg
Abhishek Bachchan
http://forbesindia.com/media/list/033_SM.jpg
Sunidhi Chauhan
http://forbesindia.com/media/list/072_SM.jpg
Shruti Haasan
http://forbesindia.com/media/list/Shruti Hassan _SM.jpg
MC Mary Kom
http://forbesindia.com/media/list/046_SM.jpg
Vishal-Shekhar
http://forbesindia.com/media/list/083_SM.jpg
Mika Singh
http://forbesindia.com/media/list/Mikka_SM.jpg
Arijit Singh
http://forbesindia.com/media/list/Arjit Singh_SM.jpg
Chetan Bhagat
http://forbesindia.com/media/list/075_SM.jpg
Rajkumar Hirani
http://forbesindia.com/media/list/Rajkumar_Hirani_SM.jpg
All India Bakchod (AIB)
http://forbesindia.com/media/list/AIB_SM.jpg
Rajinikanth
http://forbesindia.com/media/list/Rajnikanth_SM.jpg
Kabir Khan
http://forbesindia.com/media/list/Kabir Khan_SM.jpg
Suriya
http://forbesindia.com/media/list/suriya_sm.jpg
SS Rajamouli
http://forbesindia.com/media/list/Rajamouli_SM.jpg
Anurag Kashyap
http://forbesindia.com/media/list/055_SM.jpg
Ravi Teja
http://forbesindia.com/media/list/celeb_2015_sm.jpg
Anupam Kher
http://forbesindia.com/media/list/Anupam Kher_SM.jpg
Riteish Deshmukh
http://forbesindia.com/media/list/060_SM.jpg
Prabhas
http://forbesindia.com/media/list/Prabhas_SM.jpg
Irrfan Khan
http://forbesindia.com/media/list/IrrFan_SM.jpg
Bipasha Basu
http://forbesindia.com/media/list/025_SM.jpg
Arya
http://forbesindia.com/media/list/celeb_2015_sm.jpg
Farah Khan
http://forbesindia.com/media/list/Farah Khan_SM.jpg
Ajay-Atul
http://forbesindia.com/media/list/Ajay_Atul_SM.jpg
Shilpa Shetty
http://forbesindia.com/media/list/058_SM.jpg
Preity Zinta
http://forbesindia.com/media/list/Preity Zinta_SM.jpg
Leander Paes
http://forbesindia.com/media/list/LeanderPaes_SM.jpg
Salim-Sulaiman
http://forbesindia.com/media/list/Salim-Sulaiman_SM.jpg
Remo D'Souza
http://forbesindia.com/media/list/091_SM.jpg
Prabhudheva
http://forbesindia.com/media/list/PrabhU Deva_SM.jpg
Puri Jagannadh
http://forbesindia.com/media/list/celeb_2015_sm.jpg
Anirban Lahiri
http://forbesindia.com/media/list/Anirban Lahiri_SM.jpg
Shaan
http://forbesindia.com/media/list/087_SM.jpg
Sunil Chhetri
http://forbesindia.com/media/list/Sunil_Chhetri_SM.jpg
Rohan Bopanna
http://forbesindia.com/media/list/065_SM.jpg
Navjot Singh Sidhu
http://forbesindia.com/media/list/Sidhu_SM.jpg
Kirron Kher
http://forbesindia.com/media/list/095_SM.jpg
Rohit shetty
http://forbesindia.com/media/list/069_SM.jpg
Amish Tripathi
http://forbesindia.com/media/list/Amish Tripathi_SM.jpg
Mithun Chakroborty
http://forbesindia.com/media/list/084_SM.jpg
Vir Das
http://forbesindia.com/media/list/082_SM.jpg
Malaika Arora Khan
http://forbesindia.com/media/list/080_SM.jpg

enter image description here

1 个答案:

答案 0 :(得分:2)

您一次只能将一个标签/句柄组合传递给legend命令。对于给定的轴,每次调用legend都会覆盖先前对legend的调用,删除以前的图例而不是添加到现有图例。您希望使用两个绘图处理和标签来呼叫legend 一次

legend([h_A, h_Z], {'a', 'z'})

<强>更新

因为在您的情况下h_Ah_Z是具有相同外观的情节句柄数组,您只需将h_Ah_Z中的第一项传递给{{1 }}

legend