|
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 |
@@ -551,13 +552,48 @@ def draw_path(self, **props): |
551 | 552 | is_bar = mpltools.is_bar(self.current_mpl_ax.containers, **props) |
552 | 553 | if is_bar: |
553 | 554 | self.current_bars += [props] |
| 555 | + elif isinstance(props["mplobj"], mpatches.StepPatch): |
| 556 | + self.msg += " Drawing a step path\n" |
| 557 | + self._draw_step_path(props) |
554 | 558 | else: |
555 | 559 | self.msg += " This path isn't a bar, not drawing\n" |
556 | 560 | warnings.warn( |
557 | 561 | "I found a path object that I don't think is part " |
558 | 562 | "of a bar chart. Ignoring." |
559 | 563 | ) |
560 | 564 |
|
| 565 | + def _draw_step_path(self, props): |
| 566 | + """Draw a matplotlib StepPatch as a step line trace.""" |
| 567 | + if props["coordinates"] != "data": |
| 568 | + self.msg += " Step path is not in data coordinates, not drawing\n" |
| 569 | + return |
| 570 | + style = props["style"] |
| 571 | + x = [] |
| 572 | + y = [] |
| 573 | + for x0, y0 in props["data"]: |
| 574 | + if not x or x0 != x[-1] or y0 != y[-1]: |
| 575 | + x.append(x0) |
| 576 | + y.append(y0) |
| 577 | + if len(x) < 2: |
| 578 | + self.msg += " Step path has fewer than 2 points, not drawing\n" |
| 579 | + return |
| 580 | + self.plotly_fig.add_trace( |
| 581 | + go.Scatter( |
| 582 | + x=x, |
| 583 | + y=y, |
| 584 | + mode="lines", |
| 585 | + line=go.scatter.Line( |
| 586 | + color=mpltools.merge_color_and_opacity( |
| 587 | + style["edgecolor"], style["alpha"] |
| 588 | + ), |
| 589 | + width=style["edgewidth"], |
| 590 | + dash=mpltools.convert_dash(style["dasharray"]), |
| 591 | + ), |
| 592 | + xaxis="x{0}".format(self.axis_ct), |
| 593 | + yaxis="y{0}".format(self.axis_ct), |
| 594 | + ) |
| 595 | + ) |
| 596 | + |
561 | 597 | def draw_text(self, **props): |
562 | 598 | """Create an annotation dict for a text obj. |
563 | 599 |
|
|
0 commit comments