Skip to content

Commit 57c07a6

Browse files
Merge pull request #404 from plotly/fixing_issues_related_to_tick-values-labels_and_colorbar
fixing issues related to tick-values-labels and colorbar
2 parents 533fd1a + 049a778 commit 57c07a6

File tree

10 files changed

+610
-626
lines changed

10 files changed

+610
-626
lines changed

plotly/plotlyfig.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
end
9292

9393
%-PlotlyDefaults-%
94-
obj.PlotlyDefaults.MinTitleMargin = 80;
94+
obj.PlotlyDefaults.MinTitleMargin = 10;
9595
obj.PlotlyDefaults.TitleHeight = 0.01;
9696
obj.PlotlyDefaults.TitleFontSizeIncrease = 40;
9797
obj.PlotlyDefaults.FigureIncreaseFactor = 1.5;
@@ -802,7 +802,6 @@ function validate(obj)
802802
end
803803
catch
804804
% TODO to the future
805-
% disp('catch at line 679 in plotlyfig.m file')
806805
end
807806
end
808807

@@ -1122,7 +1121,7 @@ function delete(obj)
11221121
|| strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')...
11231122
|| strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')...
11241123
|| strcmpi(fieldname,'scattergeo') || strcmpi(fieldname,'scattermapbox')...
1125-
|| strcmpi(fieldname,'scatterternary')...
1124+
|| strcmpi(fieldname,'scatterternary') || strcmpi(fieldname,'colorbar')...
11261125
)
11271126
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
11281127
end

plotly/plotlyfig_aux/core/updateAxis.m

+65-22
Original file line numberDiff line numberDiff line change
@@ -42,60 +42,61 @@
4242
% position:...[NOT SUPPORTED IN MATLAB]
4343

4444
%-STANDARDIZE UNITS-%
45-
axisunits = get(obj.State.Axis(axIndex).Handle,'Units');
45+
axisUnits = get(obj.State.Axis(axIndex).Handle,'Units');
4646
set(obj.State.Axis(axIndex).Handle,'Units','normalized')
4747

4848
try
49-
fontunits = get(obj.State.Axis(axIndex).Handle,'FontUnits');
49+
fontUnits = get(obj.State.Axis(axIndex).Handle,'FontUnits');
5050
set(obj.State.Axis(axIndex).Handle,'FontUnits','points')
5151
catch
5252
% TODO
5353
end
5454

5555
%-AXIS DATA STRUCTURE-%
56-
axis_data = get(obj.State.Axis(axIndex).Handle);
56+
axisData = get(obj.State.Axis(axIndex).Handle);
5757

5858
%-------------------------------------------------------------------------%
5959

6060
%-check if headmap axis-%
61-
is_headmap_axis = isfield(axis_data, 'XDisplayData');
61+
is_headmap_axis = isfield(axisData, 'XDisplayData');
6262
obj.PlotOptions.is_headmap_axis = is_headmap_axis;
6363

6464
%-------------------------------------------------------------------------%
6565

6666
%-check if geo-axis-%
67-
isGeoaxis = isfield(axis_data, 'Type') && strcmpi(axis_data.Type, 'geoaxes');
67+
isGeoaxis = isfield(axisData, 'Type') && strcmpi(axisData.Type, 'geoaxes');
6868
obj.PlotlyDefaults.isGeoaxis = isGeoaxis;
6969

7070
%-------------------------------------------------------------------------%
7171

7272
%-xaxis-%
7373
if is_headmap_axis
74-
xaxis = extractHeatmapAxisData(obj,axis_data, 'X');
74+
xaxis = extractHeatmapAxisData(obj,axisData, 'X');
75+
xExponentFormat = 0;
7576
else
76-
xaxis = extractAxisData(obj,axis_data, 'X');
77+
[xaxis, xExponentFormat] = extractAxisData(obj,axisData, 'X');
7778
end
7879

7980
%-------------------------------------------------------------------------%
8081

8182
%-yaxis-%
8283
if is_headmap_axis
83-
yaxis = extractHeatmapAxisData(obj,axis_data, 'Y');
84+
yaxis = extractHeatmapAxisData(obj,axisData, 'Y');
85+
yExponentFormat = 0;
8486
else
85-
yaxis = extractAxisData(obj,axis_data, 'Y');
87+
[yaxis, yExponentFormat] = extractAxisData(obj,axisData, 'Y');
8688
end
8789

8890
%-------------------------------------------------------------------------%
8991

9092
%-getting and setting postion data-%
91-
92-
xo = axis_data.Position(1);
93-
yo = axis_data.Position(2);
94-
w = axis_data.Position(3);
95-
h = axis_data.Position(4);
93+
xo = axisData.Position(1);
94+
yo = axisData.Position(2);
95+
w = axisData.Position(3);
96+
h = axisData.Position(4);
9697

9798
if obj.PlotOptions.AxisEqual
98-
wh = min(axis_data.Position(3:4));
99+
wh = min(axisData.Position(3:4));
99100
w = wh;
100101
h = wh;
101102
end
@@ -114,10 +115,56 @@
114115

115116
%-------------------------------------------------------------------------%
116117

118+
%-get source axis-%
117119
[xsource, ysource, xoverlay, yoverlay] = findSourceAxis(obj,axIndex);
118120

119121
%-------------------------------------------------------------------------%
120122

123+
%-set exponent format-%
124+
anIndex = obj.State.Figure.NumTexts;
125+
126+
if yExponentFormat ~= 0
127+
anIndex = anIndex + 1;
128+
exponentText = sprintf('x10^%d', yExponentFormat);
129+
130+
obj.layout.annotations{anIndex}.text = exponentText;
131+
obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)];
132+
obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)];
133+
obj.layout.annotations{anIndex}.xanchor = 'left';
134+
obj.layout.annotations{anIndex}.yanchor = 'bottom';
135+
obj.layout.annotations{anIndex}.font.size = yaxis.tickfont.size;
136+
obj.layout.annotations{anIndex}.font.color = yaxis.tickfont.color;
137+
obj.layout.annotations{anIndex}.font.family = yaxis.tickfont.family;
138+
obj.layout.annotations{anIndex}.showarrow = false;
139+
140+
if isfield(xaxis, 'range') && isfield(yaxis, 'range')
141+
obj.layout.annotations{anIndex}.x = min(xaxis.range);
142+
obj.layout.annotations{anIndex}.y = max(yaxis.range);
143+
end
144+
end
145+
146+
if xExponentFormat ~= 0
147+
anIndex = anIndex + 1;
148+
exponentText = sprintf('x10^%d', xExponentFormat);
149+
150+
obj.layout.annotations{anIndex}.text = exponentText;
151+
obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)];
152+
obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)];
153+
obj.layout.annotations{anIndex}.xanchor = 'left';
154+
obj.layout.annotations{anIndex}.yanchor = 'bottom';
155+
obj.layout.annotations{anIndex}.font.size = xaxis.tickfont.size;
156+
obj.layout.annotations{anIndex}.font.color = xaxis.tickfont.color;
157+
obj.layout.annotations{anIndex}.font.family = xaxis.tickfont.family;
158+
obj.layout.annotations{anIndex}.showarrow = false;
159+
160+
if isfield(xaxis, 'range') && isfield(yaxis, 'range')
161+
obj.layout.annotations{anIndex}.x = max(xaxis.range);
162+
obj.layout.annotations{anIndex}.y = min(yaxis.range);
163+
end
164+
end
165+
166+
%-------------------------------------------------------------------------%
167+
121168
%-xaxis anchor-%
122169
xaxis.anchor = ['y' num2str(ysource)];
123170

@@ -145,27 +192,23 @@
145192
% update the layout field (do not overwrite source)
146193
if xsource == axIndex
147194
obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis);
148-
obj.layout = setfield(obj.layout,['scene' num2str(xsource)],scene);
149-
else
150-
195+
obj.layout = setfield(obj.layout,['scene' num2str(xsource)],scene);
151196
end
152197

153198
%-------------------------------------------------------------------------%
154199

155200
% update the layout field (do not overwrite source)
156201
if ysource == axIndex
157202
obj.layout = setfield(obj.layout,['yaxis' num2str(ysource)],yaxis);
158-
else
159-
160203
end
161204

162205
%-------------------------------------------------------------------------%
163206

164207
%-REVERT UNITS-%
165-
set(obj.State.Axis(axIndex).Handle,'Units',axisunits);
208+
set(obj.State.Axis(axIndex).Handle,'Units',axisUnits);
166209

167210
try
168-
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontunits);
211+
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontUnits);
169212
catch
170213
% TODO
171214
end

0 commit comments

Comments
 (0)