How to change the properties of a plot obtained from compare(mdl,data) function.

6 views (last 30 days)
I use "compare(mdl,data)" function. This function plots the test component degradation data in data superimposed on the most similar data sets from the historical ensemble stored in the fitted similarity model. However, the qualiy of the fiqure is not good enough. For instance, I want to double the linewidth or change the color of the lines. could you please me help me how can I do it?
Many thanks

Accepted Answer

Star Strider
Star Strider on 28 Dec 2021
I don’t have the Predictive Maintenance Toolbox so I have no direct experience with it. However it exists with the online Run feature, so I gave some effort to getting the information necessary to address the problems mentioned. It took a bit of handle spelunking, however was not as difficult as some other plot types in other MATLAB Toolboxes.
I include an example at the end on how to set the red line to have a LineWidth of 5
D1 = load('pairwiseTrainTables.mat');
pairwiseTrainTables = D1.pairwiseTrainTables;
D2 = load('pairwiseTestData.mat');
pairwiseTestData = D2.pairwiseTestData;
mdl = pairwiseSimilarityModel;
fit(mdl,pairwiseTrainTables,"Time","Condition")
figure
compare(mdl,pairwiseTestData) % Original
figure
compare(mdl,pairwiseTestData) % Test
Ax = gca;
% GetAx = get(Ax)
Kids = Ax.Children
Kids =
4×1 graphics array: Scatter Group (NumericData) Group (Ensemble) Line
Sctr = findobj(Kids, 'Type','Scatter')
Sctr =
Scatter with properties: XData: [101 109 118 120 103 75 100 117 87 96 68 77 91 95 118 101 104 94 94 96 102 106 98 66 66 105 97 96 86 107 100 130 100 105 113 106 113 93 121 96 85 119 110 100 103 108 96 100 100 109 234 271 245 276 247 243 252 245 249 231 226 258 … ] YData: [-0.1317 -0.0865 -5.2878e-04 -8.5338e-04 0.0912 0.0117 0.1048 0.1412 -0.1971 0.2141 0.0471 0.1805 0.0599 0.1069 -0.1095 -0.0849 0.0157 0.0157 0.2468 0.0916 -0.1199 -0.2090 -0.1370 -0.0089 0.0256 -0.1302 -0.2000 0.0986 0.0951 … ] ZData: [1×0 double] SizeData: 50 CData: [0 0 0] Marker: '*' MarkerEdgeColor: 'flat' MarkerFaceColor: 'none' LineWidth: 0.5000 Show all properties
Grp = Kids([2 3])
Grp =
2×1 Group array: Group (NumericData) Group (Ensemble)
Line = findobj(Kids, 'Type','Line')
Line =
3×1 Line array: Line Line (Var1) Line (Condition)
Line1 = Line(1)
Line1 =
Line with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: NaN YData: NaN ZData: [1×0 double] Show all properties
Line2 = Line(2)
Line2 =
Line (Var1) with properties: Color: [0.8500 0.3250 0.0980] LineStyle: '-' LineWidth: 1.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49] YData: [2.5151 2.3697 1.9739 1.9693 1.8888 1.7847 1.3268 1.1392 1.2581 1.1176 0.9005 0.9650 0.8049 0.7798 0.6276 0.5198 0.6444 0.6062 0.5924 0.3608 0.3176 0.3667 0.2413 0.3121 0.1728 0.2024 0.0602 -0.0102 0.1824 0.1187 0.0555 0.1120 … ] ZData: [1×0 double] Show all properties
Line3 = Line(3)
Line3 =
Line (Condition) with properties: Color: [0.5216 0.7569 0.9137] LineStyle: '-' LineWidth: 0.1000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 … ] YData: [2.6284 2.2704 2.0940 2.0546 1.9287 1.7667 1.7210 1.2396 1.3562 1.1118 0.9518 0.8609 0.9066 0.8048 0.4888 0.7082 0.6306 0.4723 0.3506 0.3290 0.2438 0.3274 0.2619 0.2410 0.2684 0.1931 0.0319 0.1226 0.1127 -0.0222 0.2237 -0.0944 … ] ZData: [1×0 double] Show all properties
Line2.LineWidth = 5; % Define Red Line To Have Width = 5
Explore and customise to produce the desired result!
.

More Answers (1)

Tanmay Das
Tanmay Das on 28 Dec 2021
Hi,
You can add formatting to your plots by adding name-value pair arguments to "compare" function. For instance, to double the linewidth or change the color of the line, to say red, you may write the following line in your code:
compare(mdl,data,'r','LineWidth',10)
  2 Comments
Sara
Sara on 28 Dec 2021
Hi,
Many Thanks. I already tried it.
But the formatting such as linewidth or color changing is not working for this function
Tanmay Das
Tanmay Das on 28 Dec 2021
Edited: Tanmay Das on 28 Dec 2021
Can you please share your reproduction steps(all the code that is required to reproduce the issue at my end) for further investigation?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!