stared / livelossplot

Live training loss plot in Jupyter Notebook for Keras, PyTorch and others
https://p.migdal.pl/livelossplot
MIT License
1.29k stars 142 forks source link

Positioning of legends #123

Closed kolban-google closed 4 years ago

kolban-google commented 4 years ago

Can we choose the position of the legend? The right middle is obscuring data (for me)

image

Bartolo1024 commented 4 years ago

You can do it with decoration of the matplotlib plugin. It contains three functions: after_subplot, before_plots, after_plots - that can be override in the plugin constructor. In that case, you should use after_subplot. Example:

import matplotlib.pyplot as plt
from livelossplot import PlotLosses
from livelossplot.outputs import MatplotlibPlot

def custom_after_subplot(self, ax: plt.Axes, group_name: str, x_label: str):
    ax.set_title(group_name)
    ax.set_xlabel(x_label)
    ax.legend(loc='lower right')

outputs = [MatplotlibPlot(after_subplot=custom_after_subplot)]
groups = {'acccuracy': ['acc', 'val_acc'], 'log-loss': ['loss', 'val_loss']}
plotlosses = PlotLosses(groups=groups, outputs=outputs)