Plot legend contours messed up

3 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by