Fix interactive plots

This commit is contained in:
allegroai 2022-09-13 15:06:45 +03:00
parent e695251dd4
commit 0b66b11d53
2 changed files with 24 additions and 17 deletions

View File

@ -133,11 +133,12 @@ class Exporter(object):
self.draw_line(ax, line) self.draw_line(ax, line)
for text in ax.texts: for text in ax.texts:
self.draw_text(ax, text) self.draw_text(ax, text)
for (text, ttp) in zip([ax.xaxis.label, ax.yaxis.label, ax.zaxis.label, ax.title], for (text, ttp) in zip(
["xlabel", "ylabel", "zlabel", "title"]): [ax.xaxis.label, ax.yaxis.label, ax.title] + ([ax.zaxis.label] if hasattr(ax, "zaxis") else []),
if(hasattr(text, "get_text") and text.get_text()): ["xlabel", "ylabel", "title"] + (["zlabel"] if hasattr(ax, "zaxis") else []),
self.draw_text(ax, text, force_trans=ax.transAxes, ):
text_type=ttp) if hasattr(text, "get_text") and text.get_text():
self.draw_text(ax, text, force_trans=ax.transAxes, text_type=ttp)
for artist in ax.artists: for artist in ax.artists:
# TODO: process other artists # TODO: process other artists
if isinstance(artist, matplotlib.text.Text): if isinstance(artist, matplotlib.text.Text):
@ -279,7 +280,7 @@ class Exporter(object):
# protected for removing _offset_position() and default to "screen" # protected for removing _offset_position() and default to "screen"
offset_order = offset_dict[getattr(collection, '_offset_position', 'screen')] offset_order = offset_dict[getattr(collection, '_offset_position', 'screen')]
self.renderer.draw_path_collection(paths=processed_paths, self.renderer.draw_path_collection(ax, paths=processed_paths,
path_coordinates=path_coords, path_coordinates=path_coords,
path_transforms=path_transforms, path_transforms=path_transforms,
offsets=offsets, offsets=offsets,

View File

@ -399,22 +399,26 @@ class PlotlyRenderer(Renderer):
marked_line = dict( marked_line = dict(
type="scatter", type="scatter",
mode=mode, mode=mode,
name=( name=(str(props["label"]) if isinstance(props["label"], six.string_types) else props["label"]),
str(props["label"]) x=props["data"][0]
if isinstance(props["label"], six.string_types) if props.get("type") == "collection" and props.get("is_3d")
else props["label"] else [xy_pair[0] for xy_pair in props["data"]],
), y=props["data"][1]
x=props["data"][0], if props.get("type") == "collection" and props.get("is_3d")
y=props["data"][1], else [xy_pair[1] for xy_pair in props["data"]],
xaxis="x{0}".format(self.axis_ct), xaxis="x{0}".format(self.axis_ct),
yaxis="y{0}".format(self.axis_ct), yaxis="y{0}".format(self.axis_ct),
line=line, line=line,
marker=marker, marker=marker,
) )
if len(props["data"]) >= 3: if props.get("is_3d"):
marked_line["z"] = props["data"][2] marked_line["z"] = (
marked_line["zaxis"] = "z{0}".format(self.axis_ct) props["data"][2]
if props.get("type") == "collection"
else [xyz_tuple[2] for xyz_tuple in props["data"]]
)
marked_line["type"] = "scatter3d" marked_line["type"] = "scatter3d"
marked_line["zaxis"] = "z{0}".format(self.axis_ct)
if self.x_is_mpl_date: if self.x_is_mpl_date:
formatter = ( formatter = (
self.current_mpl_ax.get_xaxis() self.current_mpl_ax.get_xaxis()
@ -448,7 +452,7 @@ class PlotlyRenderer(Renderer):
"images from matplotlib yet!" "images from matplotlib yet!"
) )
def draw_path_collection(self, **props): def draw_path_collection(self, ax, **props):
"""Add a path collection to data list as a scatter plot. """Add a path collection to data list as a scatter plot.
Current implementation defaults such collections as scatter plots. Current implementation defaults such collections as scatter plots.
@ -487,6 +491,8 @@ class PlotlyRenderer(Renderer):
"label": None, "label": None,
"markerstyle": markerstyle, "markerstyle": markerstyle,
"linestyle": None, "linestyle": None,
"type": "collection",
"is_3d": "3d" in str(type(ax)).split(".")[-1].lower()
} }
self.msg += " Drawing path collection as markers\n" self.msg += " Drawing path collection as markers\n"
self.draw_marked_line(**scatter_props) self.draw_marked_line(**scatter_props)