示例#1
0
文件: demo.py 项目: Garvit244/visdom
)

# boxplot
X = np.random.rand(100, 2)
X[:, 1] += 2
viz.boxplot(
    X=X,
    opts=dict(legend=['Men', 'Women'])
)

# stemplot
Y = np.linspace(0, 2 * math.pi, 70)
X = np.column_stack((np.sin(Y), np.cos(Y)))
viz.stem(
    X=X,
    Y=Y,
    opts=dict(legend=['Sine', 'Cosine'])
)

# pie chart
X = np.asarray([19, 26, 55])
viz.pie(
    X=X,
    opts=dict(legend=['Residential', 'Non-Residential', 'Utility'])
)

# mesh plot
x = [0, 0, 1, 1, 0, 0, 1, 1]
y = [0, 1, 1, 0, 0, 1, 1, 0]
z = [0, 0, 0, 0, 1, 1, 1, 1]
X = np.c_[x, y, z]
示例#2
0
        win=win,
        opts=dict(
            width=300,
            height=300,
        ),
    )

    # boxplot
    X = np.random.rand(100, 2)
    X[:, 1] += 2
    viz.boxplot(X=X, opts=dict(legend=['Men', 'Women']))

    # stemplot
    Y = np.linspace(0, 2 * math.pi, 70)
    X = np.column_stack((np.sin(Y), np.cos(Y)))
    viz.stem(X=X, Y=Y, opts=dict(legend=['Sine', 'Cosine']))

    # quiver plot
    X = np.arange(0, 2.1, .2)
    Y = np.arange(0, 2.1, .2)
    X = np.broadcast_to(np.expand_dims(X, axis=1), (len(X), len(X)))
    Y = np.broadcast_to(np.expand_dims(Y, axis=0), (len(Y), len(Y)))
    U = np.multiply(np.cos(X), Y)
    V = np.multiply(np.sin(X), Y)
    viz.quiver(
        X=U,
        Y=V,
        opts=dict(normalize=0.9),
    )

    # pie chart
示例#3
0
class VisdomPlotter(object):
    """Plots to Visdom"""
    def __init__(self, server, env_name='main', port=8097):
        self.viz = Visdom(server, port=port)
        self.env = env_name
        self.plots = {}

    def plot(self, ylabel, xlabel, legend, title_name, x, y, markers=False):
        if title_name not in self.plots.keys():
            self.plots[title_name] = self.viz.line(X=np.array([x, x]),
                                                   Y=np.array([y, y]),
                                                   env=self.env,
                                                   opts=dict(
                                                       legend=[legend],
                                                       title=title_name,
                                                       xlabel=xlabel,
                                                       ylabel=ylabel,
                                                       markers=markers,
                                                       markersymbol='plus'))
        else:
            self.viz.line(X=np.array([x]),
                          Y=np.array([y]),
                          env=self.env,
                          win=self.plots[title_name],
                          name=legend,
                          update='append')

    def plot_curve(self,
                   ylabel: str,
                   xlabel: str,
                   legend: list,
                   title_name: str,
                   x: np.array,
                   y: np.array,
                   markers=False):

        if title_name in self.plots.keys():
            # Reset plot
            self.viz.close(self.plots[title_name], env=self.env)

        self.plots[title_name] = self.viz.line(X=x,
                                               Y=y,
                                               env=self.env,
                                               opts=dict(title=title_name,
                                                         xlabel=xlabel,
                                                         ylabel=ylabel,
                                                         markers=markers,
                                                         markersymbol='plus'))

    def stem_plot(self, title_name: str, ylabel: str, xlabel: str,
                  legend: list, y: np.array, x: np.array):

        if title_name in self.plots.keys():
            # Reset plot
            self.viz.close(self.plots[title_name], env=self.env)

        self.plots[title_name] = self.viz.stem(X=x,
                                               Y=y,
                                               env=self.env,
                                               opts=dict(legend=legend,
                                                         title_name=title_name,
                                                         xlabel=xlabel,
                                                         ylabel=ylabel))

    def scatter_plot(self,
                     title_name: str,
                     x: np.array,
                     y: np.array,
                     legends=None):

        if title_name in self.plots.keys():
            # Reset plot
            self.viz.close(self.plots[title_name], env=self.env)

        y_plot = y.copy()
        y_plot += 1
        self.plots[title_name] = self.viz.scatter(X=x,
                                                  Y=y_plot,
                                                  env=self.env,
                                                  opts=dict(
                                                      title=title_name,
                                                      legends=[legends],
                                                      markersymbol='dot'))

    def vis_1d_distribution(self, pts: np.array, name: str) -> None:
        step = 0.05
        max_distance = max(pts) + step
        bins = np.arange(0.0, max_distance, step)
        hist, _ = np.histogram(pts, bins=bins)
        self.stem_plot(name, 'Samples number', name, ['dist'], bins[1:], hist)

    def plot_exist(self, title_name):
        return title_name in self.plots.keys()