Plot legend contours messed up

조회 수: 2 (최근 30일)
dormant
dormant 2025년 3월 5일
답변: dormant 2025년 3월 6일
I am creating a plot where the data to be plotted is calculated from data in a set of text files. The data is grouped for plotting based on a text string in the filenames. When I add a legend for these groupings ("clumps") the colours in teh legend are messed up.
The script is quite big and messy, so I've created a simpler test script and text files with just two clumps. These are in the attached zip file. The plot created by the test script is this:
Some of the text files don't have all the required data. The script will then try to plot [NaN NaN] for those files.
The legend is not messed up if I remove these text files. In the files provided, delete the first two "Scar" files and you get this:
Where am I going wrong?
UNfortunately, I cannot change the approach of constructing the plot from the text files. The text files are generated by other software and there can be several hundred of them, in up to 12 clumps.

채택된 답변

dormant
dormant 2025년 3월 6일
After a bit of fiddling it was clear that my overall approach was totally wrong. My script had three tiled subplots and I was dancing around tiles and text files. Then I was trying to add the legend to each tile. Modifying this script was murder.
It's much easier to read all the text files into arrays or structures first. Then do the plots. I don't know why I didn't use this approach.
Thanks to all who posted. I'll come back with a new question if I run into problems with the new approach.

추가 답변 (1개)

William Rose
William Rose 2025년 3월 5일
편집: William Rose 2025년 3월 5일
Try the attached. Good luck.
Edit: Update the script, as descirbed in my comment below.
  댓글 수: 6
Afiq Azaibi
Afiq Azaibi 2025년 3월 5일
Glad to hear my other answer was able to help, @William Rose. Thanks for bringing attention to it.
To echo the relevant information from that post, if you want certian objects to appear in a legend in a certain order, the best practice is to speicfy the objects in the legend() command. This syntax is referenced as subset in the doc and is what the William points out as my first method.
dormant
dormant 2025년 3월 6일
Thanks for that info.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by