diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index b052c768..096c849b 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -71,6 +71,8 @@ obj.PlotlyDefaults.ErrorbarWidth = 6; obj.PlotlyDefaults.ShowBaselineLegend = false; obj.PlotlyDefaults.Bargap = 0; + obj.PlotlyDefaults.CaptionMarginIncreaseFactor = 1.2; + obj.PlotlyDefaults.MinCaptionMargin = 80; %-State-% obj.State.Figure = []; @@ -347,6 +349,40 @@ function validate(obj) end end + %----ADD A CUSTOM CAPTION-----% + function obj = add_caption(obj, caption_string, varargin) + + caption.text = caption_string; + + % defaults + caption.xref = 'paper'; + caption.yref = 'paper'; + caption.xanchor = 'left'; + caption.yanchor = 'top'; + caption.x = 0.1; + caption.y = -0.05; + caption.showarrow = false; + + % inject any custom annotation specs + for n = 1:2:length(varargin) + caption = setfield(caption, varargin{n}, varargin{n+1}); + end + + % adjust the bottom margin + obj.layout.margin.b = max(obj.layout.margin.b, ... + obj.PlotlyDefaults.MinCaptionMargin); + + % add the new caption to the figure + obj.State.Figure.NumTexts = obj.State.Figure.NumTexts + 1; + obj.layout.annotations{obj.State.Figure.NumTexts} = caption; + + % update the figure state + obj.State.Text(obj.State.Figure.NumTexts).Handle = NaN; + obj.State.Text(obj.State.Figure.NumTexts).AssociatedAxis = gca; + obj.State.Text(obj.State.Figure.NumTexts).Title = false; + + end + %------------------------REST API CALL----------------------------%