Example #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)
Example #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()
Example #3
0
# inset zoom demo

from freeplot.base import FreePlot

fp = FreePlot((1, 1), (5, 4))

fp.lineplot([1, 2, 3], [4, 5, 6], label='a')
fp.lineplot([1, 2, 3], [3, 5, 7], label='b')
axins, patch, lines = fp.inset_axes(xlims=(1.9, 2.1),
                                    ylims=(4.9, 5.1),
                                    bounds=(0.1, 0.7, 0.2, 0.2),
                                    index=(0, 0),
                                    style='line')
fp.lineplot([1, 2, 3], [4, 5, 6], index=axins)
fp.lineplot([1, 2, 3], [3, 5, 7], index=axins)
# for line in lines:
#     line.set({'linewidth':5, 'alpha': 0.7})
fp.show()