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

Method draw_text

plotly/matplotlylib/renderer.py:561–684  ·  view source on GitHub ↗

Create an annotation dict for a text obj. Currently, plotly uses either 'page' or 'data' to reference annotation locations. These refer to 'display' and 'data', respectively for the 'coordinates' key used in the Exporter. Appropriate measures are taken to transform t

(self, **props)

Source from the content-addressed store, hash-verified

559 )
560
561 def draw_text(self, **props):
562 """Create an annotation dict for a text obj.
563
564 Currently, plotly uses either 'page' or 'data' to reference
565 annotation locations. These refer to 'display' and 'data',
566 respectively for the 'coordinates' key used in the Exporter.
567 Appropriate measures are taken to transform text locations to
568 reference one of these two options.
569
570 props.keys() -- [
571 'text', (actual content string, not the text obj)
572 'position', (an x, y pair, not an mpl Bbox)
573 'coordinates', ('data', 'axes', 'figure', 'display')
574 'text_type', ('title', 'xlabel', or 'ylabel')
575 'style', (style dict, see below)
576 'mplobj' (actual mpl text object)
577 ]
578
579 props['style'].keys() -- [
580 'alpha', (opacity of text)
581 'fontsize', (size in points of text)
582 'color', (hex color)
583 'halign', (horizontal alignment, 'left', 'center', or 'right')
584 'valign', (vertical alignment, 'baseline', 'center', or 'top')
585 'rotation',
586 'zorder', (precedence of text when stacked with other objs)
587 ]
588
589 """
590 self.msg += " Attempting to draw an mpl text object\n"
591 if not mpltools.check_corners(props["mplobj"], self.mpl_fig):
592 warnings.warn(
593 "Looks like the annotation(s) you are trying \n"
594 "to draw lies/lay outside the given figure size.\n\n"
595 "Therefore, the resulting Plotly figure may not be \n"
596 "large enough to view the full text. To adjust \n"
597 "the size of the figure, use the 'width' and \n"
598 "'height' keys in the Layout object. Alternatively,\n"
599 "use the Margin object to adjust the figure's margins."
600 )
601 align = props["mplobj"]._multialignment
602 if not align:
603 align = props["style"]["halign"] # mpl default
604 if "annotations" not in self.plotly_fig["layout"]:
605 self.plotly_fig["layout"]["annotations"] = []
606 if props["text_type"] == "xlabel":
607 self.msg += " Text object is an xlabel\n"
608 self.draw_xlabel(**props)
609 elif props["text_type"] == "ylabel":
610 self.msg += " Text object is a ylabel\n"
611 self.draw_ylabel(**props)
612 elif props["text_type"] == "title":
613 self.msg += " Text object is a title\n"
614 self.draw_title(**props)
615 else: # just a regular text annotation...
616 self.msg += " Text object is a normal annotation\n"
617 # Skip creating annotations for legend text when using native legend
618 if (

Callers

nothing calls this directly

Calls 5

draw_xlabelMethod · 0.95
draw_ylabelMethod · 0.95
draw_titleMethod · 0.95
transformMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected