Parallelplot hiding y values on graph

조회 수: 16 (최근 30일)
Gorkem Akgul
Gorkem Akgul 2021년 3월 29일
편집: Adam Danz 2023년 9월 20일
The parallelplot graph below looks very confusing. Is there a way that i can hide exponential numbers ? I'd like to hide every exponential number on y axes of each date.

채택된 답변

Adam Danz
Adam Danz 2021년 3월 29일
편집: Adam Danz 2023년 9월 20일
I agree with Star Strider's advice to scale the data. That will still result in y-ticks for each YRuler.
Here are two alternatives, both of which use undocumented methods tested in r2021a but may not work in future releases.
Demo 1: remove ytick for all YRulers except the first
Remove the yticks for all YRulers except the one on the far left. If the YRulers have different scales this will be misleading unless you document the scales somehwere on the figure.
% Demo data & plot
figure()
data = rand(100,5).*[1 1e-06 1e-08 1e08 1e10];
p = parallelplot(data);
% Undocumented: access YRuler and avoid warning
origState = warning('query', 'MATLAB:structOnObject');
cleanup = onCleanup(@()warning(origState));
warning('off','MATLAB:structOnObject')
S = struct(p);
clear('cleanup')
% Remove yticks for YRulers except the first
% Note that the first and second YRuler control the left-most YRuler.
drawnow() % make sure labels are written first
set(S.YRulers(3:end), 'TickLabels', '')
See addendum below for an additional required step!
Before and after:
Demo 2: change exponent notation
% Demo data & plot
figure()
data = rand(100,5).*[1 1e-06 1e-08 1e08 1e10];
p = parallelplot(data);
% Undocumented: access YRuler and avoid warning
origState = warning('query', 'MATLAB:structOnObject');
cleanup = onCleanup(@()warning(origState));
warning('off','MATLAB:structOnObject')
S = struct(p);
clear('cleanup')
% Set ytick notation for the YRulers in axis number 'n' from the left.
% Note that the first and second YRuler control the left-most YRuler.
drawnow() % make sure labels are written first
n = 2; % axis number 2
set(S.YRulers(n+1), 'TickLabelMode', 'auto', 'Exponent', -3)
% or set the TickLabelFormat
set(S.YRulers(n+1), 'TickLabelMode', 'auto', 'TickLabelFormat', '%.3f')
See addendum below for an additional required step!
Addendum: prevent auto restoration of ticks
The changes above will be lost as soon as the axes are changed in any way (e.g. resize figure). To prevent the restoration of the original ticks, disable the MarkedClean listener. This should all go toward the end of your plotting code and I haven't explored what else this may effect!!
S.AutoListeners__{1} % view the MarkedClean listener.
ans =
listener with properties:
Source: {[1×1 ParallelCoordinatesPlot]}
EventName: 'MarkedClean'
Callback: @(~,~)markedCleanCallback(pc)
Enabled: 0
Recursive: 0
% Disable the MarkedClean listener
S.AutoListeners__{1}.Enabled = false;
  댓글 수: 17
Adam Danz
Adam Danz 2021년 3월 31일
편집: Adam Danz 2021년 4월 1일
Firstly, don't use live script for development. Use it to create demos and for instructional purposes but use regular m files otherwise. They are much faster and do less buggy.
Secondly, I'm using r2021a and with every release live script gets better, especially in 21a.
Gorkem Akgul
Gorkem Akgul 2021년 4월 3일
Thanks for the effort @Adam Danz
I'd like to ask one last thing. When i group the data, the groupvariable div is very close to graph. Can i change its location ?
I tried some approaches with set function but didn't work as usual. Also I'm gonna apply the advices of you about livescripts and update my version of MATLAB.
Livescript still shows the YRulers but i save the graph as a png file and add it into livescript.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by