MCPcopy Index your code
hub / github.com/plotly/plotly.py / draw_title

Method draw_title

plotly/matplotlylib/renderer.py:686–737  ·  view source on GitHub ↗

Add a title to the current subplot in layout dictionary. If there exists more than a single plot in the figure, titles revert to 'page'-referenced annotations. props.keys() -- [ 'text', (actual content string, not the text obj) 'position', (an x,

(self, **props)

Source from the content-addressed store, hash-verified

684 self.msg += " Heck, yeah I drew that annotation\n"
685
686 def draw_title(self, **props):
687 """Add a title to the current subplot in layout dictionary.
688
689 If there exists more than a single plot in the figure, titles revert
690 to 'page'-referenced annotations.
691
692 props.keys() -- [
693 'text', (actual content string, not the text obj)
694 'position', (an x, y pair, not an mpl Bbox)
695 'coordinates', ('data', 'axes', 'figure', 'display')
696 'text_type', ('title', 'xlabel', or 'ylabel')
697 'style', (style dict, see below)
698 'mplobj' (actual mpl text object)
699 ]
700
701 props['style'].keys() -- [
702 'alpha', (opacity of text)
703 'fontsize', (size in points of text)
704 'color', (hex color)
705 'halign', (horizontal alignment, 'left', 'center', or 'right')
706 'valign', (vertical alignment, 'baseline', 'center', or 'top')
707 'rotation',
708 'zorder', (precedence of text when stacked with other objs)
709 ]
710
711 """
712 self.msg += " Attempting to draw a title\n"
713 if len(self.mpl_fig.axes) > 1:
714 self.msg += " More than one subplot, adding title as annotation\n"
715 x_px, y_px = props["mplobj"].get_transform().transform(props["position"])
716 x, y = mpltools.display_to_paper(x_px, y_px, self.plotly_fig["layout"])
717 annotation = go.layout.Annotation(
718 text=props["text"],
719 font=go.layout.annotation.Font(
720 color=props["style"]["color"], size=props["style"]["fontsize"]
721 ),
722 xref="paper",
723 yref="paper",
724 x=x,
725 y=y,
726 xanchor="center",
727 yanchor="bottom",
728 showarrow=False, # no arrow for a title!
729 )
730 self.plotly_fig["layout"]["annotations"] += (annotation,)
731 else:
732 self.msg += " Only one subplot found, adding as a plotly title\n"
733 self.plotly_fig["layout"]["title"] = props["text"]
734 title_font = dict(
735 size=props["style"]["fontsize"], color=props["style"]["color"]
736 )
737 self.plotly_fig["layout"]["title_font"] = title_font
738
739 def draw_xlabel(self, **props):
740 """Add an xaxis label to the current subplot in layout dictionary.

Callers 1

draw_textMethod · 0.95

Calls 1

transformMethod · 0.45

Tested by

no test coverage detected