Skip to content

Commit 533fd1a

Browse files
Merge pull request #403 from plotly/fixxing_issues_related_to_part-of-issue389_multiplot-case_and_multiple-y-axes_case
Fixxing issues related to part of issue389 multiplot case and multiple y axes case
2 parents 8d83e0b + bce5746 commit 533fd1a

File tree

7 files changed

+565
-50
lines changed

7 files changed

+565
-50
lines changed

plotly/plotlyfig.m

+34-9
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ function validate(obj)
582582

583583
% find axes of figure
584584
ax = findobj(obj.State.Figure.Handle,'Type','axes','-and',{'Tag','','-or','Tag','PlotMatrixBigAx','-or','Tag','PlotMatrixScatterAx', '-or','Tag','PlotMatrixHistAx'});
585+
585586
if isempty(ax)
586587
ax = gca;
587588
end
@@ -615,7 +616,7 @@ function validate(obj)
615616

616617
% update number of annotations (one title per axis)
617618
obj.State.Figure.NumTexts = length(ax);
618-
619+
619620
% find children of figure axes
620621
for a = 1:length(ax)
621622

@@ -634,18 +635,26 @@ function validate(obj)
634635
plots = findobj(ax(axrev),'-not','Type','Text','-not','Type','axes','-depth',1);
635636

636637
% get number of nbars for pie3
637-
if strcmpi(obj.PlotOptions.TreatAs, 'pie3')
638+
if ismember('pie3', lower(obj.PlotOptions.TreatAs))
638639
obj.PlotOptions.nbars{a} = 0;
639640
for i = 1:length(plots)
640-
if strcmpi(getGraphClass(plots(i)), 'surface')
641+
if ismember('surface', lower(obj.PlotOptions.TreatAs))
641642
obj.PlotOptions.nbars{a} = obj.PlotOptions.nbars{a} + 1;
642643
end
643644
end
644645
end
645646

646647
% add baseline objects
647648
baselines = findobj(ax(axrev),'-property','BaseLine');
648-
649+
650+
% check is current axes have multiple y-axes
651+
try
652+
obj.PlotlyDefaults.isMultipleYAxes(axrev) = length(ax(axrev).YAxis) == 2;
653+
catch
654+
obj.PlotlyDefaults.isMultipleYAxes(axrev) = false;
655+
end
656+
657+
% update structures for each plot in current axes
649658
for np = 1:length(plots)
650659

651660
% reverse plots
@@ -663,9 +672,19 @@ function validate(obj)
663672
end
664673

665674
% this works for pareto
666-
if length(plots) == 0
667-
if obj.State.Figure.NumPlots ~=0
675+
if length(plots) == 0 & obj.State.Figure.NumPlots ~= 0
676+
isPareto = length(ax) >= 2 & obj.State.Figure.NumPlots >= 2;
677+
isBar = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots).Class), 'line');
678+
isLine = strcmpi(lower(obj.State.Plot(obj.State.Figure.NumPlots-1).Class), 'bar');
679+
isPareto = isPareto & isBar & isLine;
680+
681+
if isPareto
668682
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
683+
else
684+
obj.State.Figure.NumPlots = obj.State.Figure.NumPlots + 1;
685+
obj.State.Plot(obj.State.Figure.NumPlots).Handle = {};
686+
obj.State.Plot(obj.State.Figure.NumPlots).AssociatedAxis = handle(ax(axrev));
687+
obj.State.Plot(obj.State.Figure.NumPlots).Class = 'nothing';
669688
end
670689
end
671690

@@ -728,6 +747,7 @@ function validate(obj)
728747

729748
% reset dataget(obj.State.Figure.Handle,'Children')
730749
obj.data = {};
750+
obj.PlotOptions.nPlots = obj.State.Figure.NumPlots;
731751

732752
% reset layout
733753
obj.layout = struct();
@@ -738,16 +758,21 @@ function validate(obj)
738758
% update axes
739759
for n = 1:obj.State.Figure.NumAxes
740760
try
741-
updateAxis(obj,n);
761+
if ~obj.PlotlyDefaults.isMultipleYAxes(n)
762+
updateAxis(obj,n);
763+
764+
else
765+
for yax = 1:2
766+
updateAxisMultipleYAxes(obj,n,yax);
767+
end
768+
end
742769
catch
743770
% TODO to the future
744771
% disp('catch at line 647 in plotlyfig.m file')
745772
end
746773
end
747774

748775
% update plots
749-
obj.PlotOptions.nPlots = obj.State.Figure.NumPlots;
750-
751776
for n = 1:obj.State.Figure.NumPlots
752777
updateData(obj,n);
753778

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
%----UPDATE AXIS DATA/LAYOUT----%
2+
3+
function obj = updateAxisMultipleYAxes(obj,axIndex,yaxIndex)
4+
5+
%-STANDARDIZE UNITS-%
6+
axisUnits = get(obj.State.Axis(axIndex).Handle,'Units');
7+
set(obj.State.Axis(axIndex).Handle,'Units','normalized')
8+
9+
try
10+
fontUnits = get(obj.State.Axis(axIndex).Handle,'FontUnits');
11+
set(obj.State.Axis(axIndex).Handle,'FontUnits','points')
12+
catch
13+
% TODO
14+
end
15+
16+
%-AXIS DATA STRUCTURE-%
17+
axisData = get(obj.State.Axis(axIndex).Handle);
18+
19+
%-------------------------------------------------------------------------%
20+
21+
%-xaxis-%
22+
xaxis = extractAxisData(obj,axisData, 'X');
23+
24+
%-------------------------------------------------------------------------%
25+
26+
%-yaxis-%
27+
[yaxis, yAxisLim] = extractAxisDataMultipleYAxes(obj, axisData, yaxIndex);
28+
29+
%-------------------------------------------------------------------------%
30+
31+
%-getting and setting postion data-%
32+
33+
xo = axisData.Position(1);
34+
yo = axisData.Position(2);
35+
w = axisData.Position(3);
36+
h = axisData.Position(4);
37+
38+
if obj.PlotOptions.AxisEqual
39+
wh = min(axisData.Position(3:4));
40+
w = wh;
41+
h = wh;
42+
end
43+
44+
%-------------------------------------------------------------------------%
45+
46+
%-xaxis domain-%
47+
xaxis.domain = min([xo xo + w],1);
48+
scene.domain.x = min([xo xo + w],1);
49+
50+
%-------------------------------------------------------------------------%
51+
52+
%-yaxis domain-%
53+
yaxis.domain = min([yo yo + h],1);
54+
scene.domain.y = min([yo yo + h],1);
55+
56+
%-------------------------------------------------------------------------%
57+
58+
[xsource, ysource, xoverlay, yoverlay] = findSourceAxis(obj, axIndex, yaxIndex);
59+
60+
%-------------------------------------------------------------------------%
61+
62+
%-xaxis anchor-%
63+
xaxis.anchor = ['y' num2str(ysource)];
64+
65+
%-------------------------------------------------------------------------%
66+
67+
%-yaxis anchor-%
68+
yaxis.anchor = ['x' num2str(xsource)];
69+
70+
%-------------------------------------------------------------------------%
71+
72+
%-xaxis overlaying-%
73+
if xoverlay
74+
xaxis.overlaying = ['x' num2str(xoverlay)];
75+
end
76+
77+
%-------------------------------------------------------------------------%
78+
79+
%-yaxis overlaying-%
80+
if yoverlay
81+
yaxis.overlaying = ['y' num2str(yoverlay)];
82+
end
83+
84+
%-------------------------------------------------------------------------%
85+
86+
% update the layout field (do not overwrite source)
87+
if xsource == axIndex
88+
obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis);
89+
end
90+
91+
%-------------------------------------------------------------------------%
92+
93+
% update the layout field (do not overwrite source)
94+
obj.layout = setfield(obj.layout,['yaxis' num2str(ysource)],yaxis);
95+
96+
%-------------------------------------------------------------------------%
97+
98+
%-REVERT UNITS-%
99+
set(obj.State.Axis(axIndex).Handle,'Units',axisUnits);
100+
101+
try
102+
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontUnits);
103+
catch
104+
% TODO
105+
end
106+
107+
%-------------------------------------------------------------------------%
108+
109+
%-do y-axes visibles-%
110+
obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1;
111+
plotIndex = obj.PlotOptions.nPlots;
112+
113+
obj.data{plotIndex}.type = 'scatter';
114+
obj.data{plotIndex}.xaxis = ['x' num2str(xsource)];
115+
obj.data{plotIndex}.yaxis = ['y' num2str(ysource)];
116+
117+
%-------------------------------------------------------------------------%
118+
end

plotly/plotlyfig_aux/core/updateData.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
case 'quivergroup'
138138
updateQuivergroup(obj, dataIndex);
139139
case 'scatter'
140-
if strcmpi(obj.State.Axis(dataIndex).Handle.Type, 'polaraxes')
140+
if ismember('polaraxes', lower(obj.PlotOptions.TreatAs))
141141
updateScatterPolar(obj, dataIndex);
142142
elseif obj.PlotlyDefaults.isGeoaxis
143143
updateGeoScatter(obj, dataIndex);

plotly/plotlyfig_aux/handlegraphics/updateLineseries.m

+29-19
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ function updateLineseries(obj,plotIndex)
5454
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
5555

5656
%-PLOT DATA STRUCTURE- %
57-
plot_data = get(obj.State.Plot(plotIndex).Handle);
57+
plotData = get(obj.State.Plot(plotIndex).Handle);
5858

5959
%-CHECK FOR MULTIPLE AXES-%
60-
[xsource, ysource] = findSourceAxis(obj,axIndex);
60+
try
61+
for yax = 1:2
62+
yaxIndex(yax) = sum(plotData.Parent.YAxis(yax).Color == plotData.Color);
63+
end
64+
65+
[~, yaxIndex] = max(yaxIndex);
66+
[xsource, ysource] = findSourceAxis(obj, axIndex, yaxIndex);
67+
68+
catch
69+
[xsource, ysource] = findSourceAxis(obj,axIndex);
70+
end
6171

6272
%-AXIS DATA-%
6373
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
@@ -67,13 +77,13 @@ function updateLineseries(obj,plotIndex)
6777

6878
%-if polar plot or not-%
6979
treatas = obj.PlotOptions.TreatAs;
70-
ispolar = strcmpi(treatas, 'compass') || strcmpi(treatas, 'ezpolar');
80+
ispolar = ismember('compass', lower(treatas)) || ismember('ezpolar', lower(treatas));
7181

7282
%-------------------------------------------------------------------------%
7383

7484
%-getting data-%
75-
x = plot_data.XData;
76-
y = plot_data.YData;
85+
x = plotData.XData;
86+
y = plotData.YData;
7787

7888
%-------------------------------------------------------------------------%
7989

@@ -97,7 +107,7 @@ function updateLineseries(obj,plotIndex)
97107
%-------------------------------------------------------------------------%
98108

99109
%-scatter visible-%
100-
obj.data{plotIndex}.visible = strcmp(plot_data.Visible,'on');
110+
obj.data{plotIndex}.visible = strcmp(plotData.Visible,'on');
101111

102112
%-------------------------------------------------------------------------%
103113

@@ -117,21 +127,21 @@ function updateLineseries(obj,plotIndex)
117127
theta = atan2(x,y);
118128
obj.data{plotIndex}.theta = -(rad2deg(theta) - 90);
119129
else
120-
obj.data{plotIndex}.y = plot_data.YData;
130+
obj.data{plotIndex}.y = plotData.YData;
121131
end
122132

123133
%-------------------------------------------------------------------------%
124134

125135
%-Fro 3D plots-%
126136
obj.PlotOptions.is3d = false; % by default
127137

128-
if isfield(plot_data,'ZData')
138+
if isfield(plotData,'ZData')
129139

130-
numbset = unique(plot_data.ZData);
140+
numbset = unique(plotData.ZData);
131141

132-
if any(plot_data.ZData) && length(numbset)>1
142+
if any(plotData.ZData) && length(numbset)>1
133143
%-scatter z-%
134-
obj.data{plotIndex}.z = plot_data.ZData;
144+
obj.data{plotIndex}.z = plotData.ZData;
135145

136146
%-overwrite type-%
137147
obj.data{plotIndex}.type = 'scatter3d';
@@ -144,17 +154,17 @@ function updateLineseries(obj,plotIndex)
144154
%-------------------------------------------------------------------------%
145155

146156
%-scatter name-%
147-
obj.data{plotIndex}.name = plot_data.DisplayName;
157+
obj.data{plotIndex}.name = plotData.DisplayName;
148158

149159
%-------------------------------------------------------------------------%
150160

151161
%-scatter mode-%
152-
if ~strcmpi('none', plot_data.Marker) ...
153-
&& ~strcmpi('none', plot_data.LineStyle)
162+
if ~strcmpi('none', plotData.Marker) ...
163+
&& ~strcmpi('none', plotData.LineStyle)
154164
mode = 'lines+markers';
155-
elseif ~strcmpi('none', plot_data.Marker)
165+
elseif ~strcmpi('none', plotData.Marker)
156166
mode = 'markers';
157-
elseif ~strcmpi('none', plot_data.LineStyle)
167+
elseif ~strcmpi('none', plotData.LineStyle)
158168
mode = 'lines';
159169
else
160170
mode = 'none';
@@ -165,17 +175,17 @@ function updateLineseries(obj,plotIndex)
165175
%-------------------------------------------------------------------------%
166176

167177
%-scatter line-%
168-
obj.data{plotIndex}.line = extractLineLine(plot_data);
178+
obj.data{plotIndex}.line = extractLineLine(plotData);
169179

170180
%-------------------------------------------------------------------------%
171181

172182
%-scatter marker-%
173-
obj.data{plotIndex}.marker = extractLineMarker(plot_data);
183+
obj.data{plotIndex}.marker = extractLineMarker(plotData);
174184

175185
%-------------------------------------------------------------------------%
176186

177187
%-scatter showlegend-%
178-
leg = get(plot_data.Annotation);
188+
leg = get(plotData.Annotation);
179189
legInfo = get(leg.LegendInformation);
180190

181191
switch legInfo.IconDisplayStyle

plotly/plotlyfig_aux/helpers/extractAxisData.m

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@
5353
axis.tickcolor = axiscol;
5454
%-axis tickfont-%
5555
axis.tickfont.color = axiscol;
56+
5657
%-axis grid color-%
57-
axis.gridcolor = axiscol;
58+
try
59+
axis.gridcolor = sprintf('rgba(%f,,%f,%f,%f)', 255*axis_data.GridColor, axis_data.GridAlpha);
60+
catch
61+
axis.gridcolor = axiscol;
62+
end
5863

5964
%-------------------------------------------------------------------------%
6065

@@ -170,6 +175,7 @@
170175
%-------------------------------------------------------------%
171176

172177
if isnumeric(dataLim)
178+
% axis.title = 'axis';
173179
axis.range = dataLim;
174180

175181
%-------------------------------------------------------------%

0 commit comments

Comments
 (0)