필터 지우기
필터 지우기

How to keep the order in plotting scatter plot with categorical variables

조회 수: 6 (최근 30일)
Chugh
Chugh 2018년 6월 5일
답변: M_A_C 2024년 8월 12일 15:53
Hi,
I am using scatter (b,a) where a is categorical variable and b is double. The plot shows a different order than in my list in a. How do I keep the same order in the plot?

답변 (2개)

KSSV
KSSV 2018년 6월 5일
Have a look on gscatter

M_A_C
M_A_C 2024년 8월 12일 15:53
Hello Chung,
Here is a solution from my painful own experience:
If a (generally x-axis) is categorical, you should fix its order first.
For example, my categorical column has the following values: BL01-3s-3r MP01-3s-3r MPAP00W01-3s-3r MPAP00W02-3s-3r MPAP00W03-3s-3r MPAP00W04-3s-3r MPAP00W05-3s-3r MPAP00W06-3s-3r MPAP05W07-3s-3r MPAP10W08-3s-3r MPAP15W09-3s-3r MPAP20W10-3s-3r BL02-3s-3r. scatter function reorders the data in alphabetical order and moves BL02-3s-3r to the second place. See plot below:
I solved it creating a : valueset = {'BL01-3s-3r','MP01-3s-3r','MPAP00W01-3s-3r','MPAP00W02-3s-3r','MPAP00W03-3s-3r','MPAP00W04-3s-3r','MPAP00W05-3s-3r','MPAP00W06-3s-3r','MPAP05W07-3s-3r','MPAP10W08-3s-3r','MPAP15W09-3s-3r','MPAP20W10-3s-3r','BL02-3s-3r'};
then T.Channel1_E1E2 = categorical(T.Channel1_E1E2,valueset,'Ordinal',true); I use table istead. See plot below:
NOTE: If you use gscatter as KSSV recommends, you end up getting an error message like this one:
Error using gscatter
The value of 'x' is invalid. It must satisfy the function:
@(x)isnumeric(x)||isdatetime(x)||isduration(x)||iscalendarduration(x)||iscategorical(x).
Hope this help.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by