How to have legend coloured according to data
4 ビュー (過去 30 日間)
古いコメントを表示
alejandro paradiso
2023 年 2 月 3 日
コメント済み: alejandro paradiso
2023 年 2 月 3 日
Good Morning to all,
I've created a scatter plot with week days on the x and counter on the y axis. now i've get the graph with marker coloured according to weekday. my struggle is to have the legend following the weekday too. I've tried to treat legend as object, but i cannot get the result![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1284205/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1284205/image.png)
thank you
2 件のコメント
Dave
2023 年 2 月 3 日
Alejandro, quick clarification. Are the colors in your scatter plot really colored according the weekday or are they colored according to the counter reading?
採用された回答
Walter Roberson
2023 年 2 月 3 日
I suggest you consider using gscatter
Otherwise, you have two possibilities:
- use one scatter() call for each different group, so that one scatter object is created per group. Each scatter object can have its own legend entry; or
- use only a single scatter() call with the "color" parameter set according to day of the week. But then use h(K) = scatter(nan,nan,[],COLOR); repeatedly to add additional invisible scatter objects. Then pass that handle h to legend() as the first parameter, so that it will create legend entries only for those (invisible) objects.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!