Skip to content
Snippets Groups Projects
Commit 77e33781 authored by Wu, Yali's avatar Wu, Yali
Browse files

add subplots

parent 827711b4
No related branches found
No related tags found
1 merge request!18Draft: Resolve "Deserialize subplots"
Pipeline #1099733 passed
import numpy as np
import matplotlib.pyplot as plt
from plotid.tagplot import tagplot
from plot_serializer.serializer import Serializer
from plot_serializer.deserializer import Deserializer
np.random.seed(19680801)
X = np.linspace(0.5, 3.5, 100)
Y1 = 3 + np.cos(X)
Y2 = 1 + np.cos(1 + X / 0.75) / 2
Y3 = np.random.uniform(Y1, Y2, len(X))
# fig1 = plt.figure(figsize=(7.5, 7.5))
# ax = fig1.add_axes([0.2, 0.17, 0.68, 0.7], aspect=1)
# ax2 = fig1.add_axes([0.3, 0.2, 0.8, 0.9], aspect=2)
# fig,axs = plt.subplots(2,1)
# ax.set_xlim(0, 4)
# ax.set_ylim(0, 4)
# ax.tick_params(which="major", width=1.0, length=10, labelsize=14)
# ax.tick_params(which="minor", width=1.0, length=5, labelsize=10, labelcolor="0.25")
# ax.grid(linestyle="--", linewidth=0.5, color=".25", zorder=-10)
# axs[0].plot(X, Y1, c="C0", lw=2.5, label="Blue signal", zorder=10)
# axs[0].plot(X, Y2, c="C1", lw=2.5, label="Orange signal")
# # ax.scatter(X[::3], Y3[::3], label="scatter")
# ax.set_title("Example figure", fontsize=20, verticalalignment="bottom")
# ax.set_xlabel("TIME in s", fontsize=14)
# ax.set_ylabel("DISTANCE in m", fontsize=14)
# ax.legend(loc="upper right", fontsize=14)
# fig2 = plt.subplots(figsize=(7.5, 7.5))
# ax2 = fig2.add_axes([0.2, 0.17, 0.68, 0.7], aspect=1)
# axs[1].plot(X, Y1 * 2, c="C0", lw=2.5, label="Blue signal", zorder=10)
# axs[1].plot(X, Y2 * 2, c="C1", lw=2.5, label="Orange signal")
# plotids = tagplot(
# [fig1, fig2], "matplotlib", prefix="id:", id_method="random", location="southeast"
# )
fig,axs = plt.subplots(2,1)
axs[0].plot(X, Y1, c="C0", lw=2.5, label="Blue signal", zorder=10)
axs[0].plot(X, Y2, c="C1", lw=2.5, label="Orange signal")
axs[1].plot(X, Y1 * 2, c="C3", lw=2.5, label="Blue signal", zorder=10)
axs[1].plot(X, Y2 * 2, c="C4", lw=2.5, label="Orange signal")
# fig = plt.figure()
# ax1 = fig.add_axes([0.1, 0.8, 0.8, 0.4])
# ax2 = fig.add_axes([0.1, 0.2, 0.8, 0.4])
# ax1.plot(X, Y1, c="C0", lw=2.5, label="Blue signal", zorder=10)
# ax1.plot(X, Y2, c="C1", lw=2.5, label="Orange signal")
# ax2.plot(X, Y1, c="C3", lw=2.5, label="Blue signal", zorder=10)
# ax2.plot(X, Y2, c="C4", lw=2.5, label="Orange signal")
s = Serializer(fig)
# s.plot.id = plotids.figure_ids[0]
# s.plot.axes[0].xunit = "second"
# s.plot.axes[0].yunit = "meter"
s.add_custom_metadata({"date_created": "22.08.2023"}, s.plot)
s.add_plot_metadata("1","title1","test")
s.add_axis_metadata(0,"title0","xlabel","ylabel")
s.add_axis_metadata(1,"title1","xlabel","ylabel")
json_object_1 = s.to_json()
# s2 = Serializer(fig2)
# # s2.add_id(plotids.figure_ids[1])
# s2.add_custom_metadata({"date_created": "11.08.2023"},s2.plot)
# json_object_2 = s2.to_json()
with open("test_plot.json", "w") as outfile:
outfile.write(json_object_1)
# outfile.write(json_object_2)
ds = Deserializer()
fig = ds.json_to_matplotlib("test_plot.json")
fig.show()
plt.show()
pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment