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)
def imagemeter(*imgs): rows = len(imgs) cols = imgs[0].shape[0] fp = FreePlot((rows, cols), (cols, rows), dpi=100) for row in range(rows): for col in range(cols): fp.imageplot(imgs[row][col], index=row * cols + col) return fp.fig
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.)
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()
# 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()
""" heatmap demo """ import numpy as np import pandas as pd import matplotlib.pyplot as plt from freeplot.base import FreePlot titles = ("S", "h", "a", "n") row_labels = ('c', 'u', 't', 'e') col_labels = ('l', 'r', 'i', 'g') # shape: 1, 4; figsize: 9, 2 fp = FreePlot((1, 4), (9, 2), titles=titles, dpi=100, sharey=True) for title in titles: data = np.random.rand(4, 4) df = pd.DataFrame(data, index=col_labels, columns=row_labels) fp.heatmap(df, index=title, annot=True, fmt=".4f", cbar=False, linewidth=0.5) fp.set(Xlabel="X") fp.set_label('Y', index=(0, 0), axis='y') fp.savefig("heatmap_demo.pdf", format="pdf", tight_layout=False) # plt.show()
import numpy as np import matplotlib.pyplot as plt import seaborn as sns from freeplot.base import FreePlot from freeplot.zoo import pre_radar, pos_radar labels = ("brightness", "defocus_blur", "fog", "gaussian_blur", "glass_blur", "jpeg_compression", "motion_blur", "saturate, snow", "speckle_noise", "contrast", "elastic_transform", "frost", "gaussian_noise", "impulse_noise", "pixelate", "shot_noise", "spatter", "zoom_blur", "transform", "flowSong") theta = pre_radar(len(labels), frame="polygon") # shape: 1, 1; figsize: 4, 4; fp = FreePlot((1, 1), (4, 4), dpi=100, titles=["RADAR"], projection="radar") data = { "A": np.random.rand(len(labels)), 'B': np.random.rand(len(labels)), 'C': np.random.rand(len(labels)) } pos_radar(data, labels, fp) fp[0, 0].legend() # fp.savefig("radar_demo.pdf", format="pdf", tight_layout=True) plt.show()
import numpy as np import matplotlib.pyplot as plt import seaborn as sns from freeplot.base import FreePlot from scipy.stats import multivariate_normal normal = multivariate_normal titles = ("S", "h", "a", "n") labels = ("sin", "cos", "x") # shape: 1, 4; figsize: 9.5, 2 fp = FreePlot((1, 4), (9.5, 2), titles=titles, dpi=100, sharey=True) nums = 100 means = ((0, 0), (5, 5), (-5, -5)) cov = (2, 1, 1) for title in titles: for i, mean in enumerate(means): data = normal.rvs(mean, cov[i], size=nums) fp.scatterplot(data[:, 0], data[:, 1], index=title, label=labels[i]) fp.set_title(y=1.) fp.set_label("Y", index=(0, 0), axis='y') fp.set_label("X", index=None, axis='x') fp[0, 0].legend() # fp.savefig("scatter_demo.pdf", format="pdf", tight_layout=False) plt.show()
from mpl_toolkits import axisartist import json import os import sys import seaborn as sns from freeplot.base import FreePlot A = [1., 2., 3.] B = [2., 3., 4.] T = ['One', 'Two', 'Three'] * 2 Hue = ['A'] * len(A) + ['B'] * len(B) data = pd.DataFrame( { "T": T, "val": A + B, "category": Hue } ) # shape: 1, 1; figsize: 2.2, 2 fp = FreePlot((1, 1), (2.2, 2), titles=("Bar Demo",), dpi=200) fp.barplot(x='T', y='val', hue='category', data=data, index=(0, 0), auto_fmt=True) fp.set(xlabel='X') fp.set_label('Y', index=(0, 0), axis='y') fp[0, 0].legend(ncol=2) # fp.savefig("heatmap_demo.pdf", format="pdf", tight_layout=False) plt.show()