diff --git a/plotshop/fig_editor/main.py b/plotshop/fig_editor/main.py index f894c891e..060167132 100644 --- a/plotshop/fig_editor/main.py +++ b/plotshop/fig_editor/main.py @@ -17,10 +17,11 @@ def main(): form.show() app.exec_() + def quick_figure(): import matplotlib.pyplot as plt fig = plt.figure() - plt.text(.5,.5, "Hallo") + plt.text(.5, .5, "Hallo") plt.errorbar(range(3), range(3), yerr=range(3), xerr=range(3), capsize=3) return fig diff --git a/plotshop/fig_editor/options_artists.py b/plotshop/fig_editor/options_artists.py index 1b802f91c..d504a726e 100644 --- a/plotshop/fig_editor/options_artists.py +++ b/plotshop/fig_editor/options_artists.py @@ -18,6 +18,7 @@ import options_utils as outils from general_helper import suppress_exception + def change_properties(artist, parent=None): """ Change the properties of artist via user interface. """ regen_legend = False @@ -110,7 +111,6 @@ def _get_axis_properties(axis): grid_style_data = outils.prepare_formdata(outils.get_linestyles(), grid_style) - # find limits lim = axis.axes.__getattribute__("get_{}lim".format(plane))() set_lim_func = axis.axes.__getattribute__("set_{}lim".format(plane)) @@ -251,7 +251,10 @@ def _get_ebar_properties(ebar): props += _get_line_properties(ebar[0])[0][3:] if bar is not None: - ls = "-" # TODO: Could not find the proper way to return the linestyle + ls = bar.get_linestyles()[0][0] + if ls is None: + ls = "None" # it seems as if None here is "Solid" for some reason. + # Workaround: set width to 0 ls_def, ls_choices = outils.prepare_formdata(outils.get_linestyles(), ls) diff --git a/plotshop/fig_editor/serialization.py b/plotshop/fig_editor/serialization.py index 1ab77ad3a..bc37c5d0e 100644 --- a/plotshop/fig_editor/serialization.py +++ b/plotshop/fig_editor/serialization.py @@ -1,9 +1,71 @@ from utils.contexts import suppress_exception +from utils.dict_tools import DotDict + + def line_to_struct(line): - pass + """ Converts a line to a dictionary structure of plotly-standard. + See https://plot.ly/python/reference/#scatter + """ + ls = DotDict() + ls.name = line.get_name() + ls.visible = line.get_visible() + ls.x = line.get_xdata() + ls.y = line.get_ydata() + ls.mode = _get_mode(line) + + ls.line = DotDict() + ls.line.color = line.get_color() + ls.line.width = line.get_width() + ls.line.dash = line.get_linestyle() def struct_to_line(ax, struct): pass + + + +def linestyle_to_dash(ls): + """ Map linestyle to dash_names """ + return { + "-": "solid", + "--": "dash", + ".": "dot", + "-.": "dashdot", + }[ls] + + +def dash_to_linestyle(dash): + try: + return { + "solid": "-", + "dash": "--", + "dot": ".", + "dashdot": "-.", + "longdash": "--", + "longdashdot": "-.", + }[dash] + except KeyError: + return "--" + + +def _get_mode(line): + """ Returns 'lines', 'markers' or 'lines+markers'. + """ + mode = [] + ls = line.get_linestyle() + ms = line.get_marker() + if "none" != ls.lower(): + mode.append("lines") + if "none" != ms.lower(): + mode.append("markers") + return "+".join(mode) + + +def _set_mode(line, mode): + """ Sets lines or markers to None if not in mode. """ + if "lines" not in mode: + line.set_linestyle("None") + if "markers" not in mode: + line.set_marker("None") \ No newline at end of file