Esempio n. 1
0
class ImageMeter:
    def __init__(self, *meters: TrackMeter, title: str = ""):
        from freeplot.base import FreePlot
        self.meters = list(meters)
        self.title = title
        self.fp = FreePlot(shape=(1, 1),
                           figsize=(2.2, 2),
                           titles=(title, ),
                           dpi=300)
        # self.fp.set_label("Val", axis='y')
        # self.fp.set_label("T", axis='x')
        self.fp.set_title(y=1.)

    def add(self, *meters: TrackMeter) -> None:
        self.meters += list(meters)

    def plot(self) -> None:
        for meter in self.meters:
            x = meter.timeline
            y = meter.history
            self.fp.lineplot(x, y, label=meter.name)
        self.fp[0].legend()
        self.fp.savefig
        plt.tight_layout()

    def save(self, writter: 'SummaryWriter', postfix: str = '') -> None:
        filename = f"{self.title}{postfix}"
        writter.add_figure(filename, self.fp.fig)
Esempio n. 2
0
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from freeplot.base import FreePlot

titles = ("S", "h", "a", "n")
labels = ("sin", "cos", "x")
fp = FreePlot((1, 4), (9.5, 2), titles=titles, dpi=100, sharey=True)

nums = 20
x = np.linspace(-10, 10, nums)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = x
ys = (y1, y2, y3)

for title in titles:
    for i, y in enumerate(ys):
        y = y + np.random.randn(nums)
        fp.lineplot(x, y, index=title, label=labels[i])

fp.set_title(y=1.)
fp.set_label("y", axis='y')
fp.set(Xlabel="x")
fp[0, 0].legend()
# fp.savefig("line_demo.pdf", format="pdf", tight_layout=False)
plt.show()