How to have legend coloured according to data

조회 수: 4 (최근 30일)
alejandro paradiso
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
thank you
  댓글 수: 2
Dave
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?
alejandro paradiso
alejandro paradiso 2023년 2월 3일
편집: alejandro paradiso 2023년 2월 3일
monthlyAccidents=groupsummary(data,["AccidentMonth","AccidentWeekDay2"])
monthlyScatter=scatter(monthlyAccidents.AccidentMonth,monthlyAccidents.GroupCount,30,monthlyAccidents.AccidentWeekDay2,"filled")

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

채택된 답변

Walter Roberson
Walter Roberson 2023년 2월 3일
I suggest you consider using gscatter
Otherwise, you have two possibilities:
  1. 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
  2. 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 CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by