Skip to content

Commit ec7506c

Browse files
committed
Merge pull request #59 from plotly/plotly_captions_wrapper
introduce caption helper method
2 parents 78e0d75 + 21992c2 commit ec7506c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

plotly/plotlyfig.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
obj.PlotlyDefaults.ErrorbarWidth = 6;
7272
obj.PlotlyDefaults.ShowBaselineLegend = false;
7373
obj.PlotlyDefaults.Bargap = 0;
74+
obj.PlotlyDefaults.CaptionMarginIncreaseFactor = 1.2;
75+
obj.PlotlyDefaults.MinCaptionMargin = 80;
7476

7577
%-State-%
7678
obj.State.Figure = [];
@@ -347,6 +349,40 @@ function validate(obj)
347349
end
348350
end
349351

352+
%----ADD A CUSTOM CAPTION-----%
353+
function obj = add_caption(obj, caption_string, varargin)
354+
355+
caption.text = caption_string;
356+
357+
% defaults
358+
caption.xref = 'paper';
359+
caption.yref = 'paper';
360+
caption.xanchor = 'left';
361+
caption.yanchor = 'top';
362+
caption.x = 0.1;
363+
caption.y = -0.05;
364+
caption.showarrow = false;
365+
366+
% inject any custom annotation specs
367+
for n = 1:2:length(varargin)
368+
caption = setfield(caption, varargin{n}, varargin{n+1});
369+
end
370+
371+
% adjust the bottom margin
372+
obj.layout.margin.b = max(obj.layout.margin.b, ...
373+
obj.PlotlyDefaults.MinCaptionMargin);
374+
375+
% add the new caption to the figure
376+
obj.State.Figure.NumTexts = obj.State.Figure.NumTexts + 1;
377+
obj.layout.annotations{obj.State.Figure.NumTexts} = caption;
378+
379+
% update the figure state
380+
obj.State.Text(obj.State.Figure.NumTexts).Handle = NaN;
381+
obj.State.Text(obj.State.Figure.NumTexts).AssociatedAxis = gca;
382+
obj.State.Text(obj.State.Figure.NumTexts).Title = false;
383+
384+
end
385+
350386

351387
%------------------------REST API CALL----------------------------%
352388

0 commit comments

Comments
 (0)