Skip to content
Snippets Groups Projects

Draft: Resolve "Add legend to deserialized plot"

Closed Wu, Yali requested to merge 7-add-legend-to-deserialized-plot into main
1 unresolved thread
3 files
+ 12
60
Compare changes
  • Side-by-side
  • Inline

Files

@@ -10,14 +10,6 @@ class Deserializer:
pass
def from_json(self, filename):
"""Creates a Plot object out of a JSON file created with Serializer.
Args:
filename (str): path to the JSON file
Returns:
plot_serializer.Plot: Plot object from the JSON file
"""
with open(filename, "r") as openfile:
# Reading from json file
d = json.load(openfile)
@@ -25,6 +17,9 @@ class Deserializer:
p.axes = []
for a in d["axes"]:
axis = Axis()
axis.xlabel = a["xlabel"]
axis.ylabel = a["ylabel"]
axis.title = a['title']
axis.traces = []
for t in a["traces"]:
plotted_element = Trace()
@@ -50,6 +45,11 @@ class Deserializer:
fig = plt.figure()
for axis in self.plot.axes:
ax = fig.add_subplot()
ax.set_xlabel(axis.xlabel)
ax.set_ylabel(axis.ylabel)
ax.set_title(axis.title)
for t in axis.traces:
ax.plot(t.xdata, t.ydata, label=t.label, color=t.color)
ax.legend()
fig.tight_layout()
return fig
Loading