|
9 | 9 |
|
10 | 10 | import warnings |
11 | 11 |
|
| 12 | +import matplotlib.patches as mpatches |
12 | 13 | import plotly.graph_objs as go |
13 | 14 | from plotly.matplotlylib.mplexporter import Renderer |
14 | 15 | from plotly.matplotlylib import mpltools |
@@ -602,13 +603,48 @@ def draw_path(self, **props): |
602 | 603 | is_bar = mpltools.is_bar(self.current_mpl_ax.containers, **props) |
603 | 604 | if is_bar: |
604 | 605 | self.current_bars += [props] |
| 606 | + elif isinstance(props["mplobj"], mpatches.StepPatch): |
| 607 | + self.msg += " Drawing a step path\n" |
| 608 | + self._draw_step_path(props) |
605 | 609 | else: |
606 | 610 | self.msg += " This path isn't a bar, not drawing\n" |
607 | 611 | warnings.warn( |
608 | 612 | "I found a path object that I don't think is part " |
609 | 613 | "of a bar chart. Ignoring." |
610 | 614 | ) |
611 | 615 |
|
| 616 | + def _draw_step_path(self, props): |
| 617 | + """Draw a matplotlib StepPatch as a step line trace.""" |
| 618 | + if props["coordinates"] != "data": |
| 619 | + self.msg += " Step path is not in data coordinates, not drawing\n" |
| 620 | + return |
| 621 | + style = props["style"] |
| 622 | + x = [] |
| 623 | + y = [] |
| 624 | + for x0, y0 in props["data"]: |
| 625 | + if not x or x0 != x[-1] or y0 != y[-1]: |
| 626 | + x.append(x0) |
| 627 | + y.append(y0) |
| 628 | + if len(x) < 2: |
| 629 | + self.msg += " Step path has fewer than 2 points, not drawing\n" |
| 630 | + return |
| 631 | + self.plotly_fig.add_trace( |
| 632 | + go.Scatter( |
| 633 | + x=x, |
| 634 | + y=y, |
| 635 | + mode="lines", |
| 636 | + line=go.scatter.Line( |
| 637 | + color=mpltools.merge_color_and_opacity( |
| 638 | + style["edgecolor"], style["alpha"] |
| 639 | + ), |
| 640 | + width=style["edgewidth"], |
| 641 | + dash=mpltools.convert_dash(style["dasharray"]), |
| 642 | + ), |
| 643 | + xaxis="x{0}".format(self.axis_ct), |
| 644 | + yaxis="y{0}".format(self.axis_ct), |
| 645 | + ) |
| 646 | + ) |
| 647 | + |
612 | 648 | def draw_text(self, **props): |
613 | 649 | """Create an annotation dict for a text obj. |
614 | 650 |
|
|
0 commit comments