def demo_fixed_pad_axes(): fig = plt.figure(2, (6, 6)) # The first & third items are for padding and the second items are for the axes. # sizes are in inch. h = [ Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2), ] v = [ Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5), ] divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False) # the width and height of the rectangle is ignored. ax = LocatableAxes(fig, divider.get_position()) ax.set_axes_locator(divider.new_locator(nx=1, ny=1)) fig.add_axes(ax) ax.plot([1, 2, 3])
def demo_fixed_pad_axes(): fig = plt.figure(2, (6, 6)) # The first & third items are for padding and the second items are for the # axes. Sizes are in inches. h = [Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2)] v = [Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5)] divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False) # the width and height of the rectangle is ignored. ax = LocatableAxes(fig, divider.get_position()) ax.set_axes_locator(divider.new_locator(nx=1, ny=1)) fig.add_axes(ax) ax.plot([1, 2, 3])
def demo_fixed_size_axes(): fig1 = plt.figure(1, (10, 5)) # The first items are for padding and the second items are for the axes. # sizes are in inch. h = [Size.Fixed(1.0), Size.Fixed(7.5)] v = [Size.Fixed(0.7), Size.Fixed(4.5)] divider = Divider(fig1, (0.0, 0.0, 1., 1.), h, v, aspect=False) # the width and height of the rectangle is ignored. ax = LocatableAxes(fig1, divider.get_position()) ax.set_axes_locator(divider.new_locator(nx=1, ny=1)) fig1.add_axes(ax) ax.plot([1, 2, 3])
def plot_variance_multi(savefile, data, labels, colors, ylabel, ylim, ylim_unit=1, ylim_scale=5, colors2=None, hline=None, vline=None, locator=-1, draw_dist=True, subsample=1): plt.clf() plt.rcParams["font.size"] = 14 colors2 = colors if colors2 is None else colors2 m = len(data) #fig, ax = plt.subplots(1, 1) fig = plt.figure(1, figsize=(4, 4)) # The first items are for padding and the second items are for the axes. # sizes are in inch. h = [Size.Fixed(0.65), Size.Fixed(5.5)] v = [Size.Fixed(0.7), Size.Fixed(4.)] divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False) # the width and height of the rectangle is ignored. ax = LocatableAxes(fig, divider.get_position()) ax.set_axes_locator(divider.new_locator(nx=1, ny=1)) fig.add_axes(ax) if not hasattr(draw_dist, '__getitem__'): v = draw_dist draw_dist = [v for i in range(m)] print(draw_dist) for k in range(m)[::-1]: plot_m = numpy.median(data[k], 0) sorted = numpy.sort(data[k], 0) n = data[k].shape[0] T = data[k].shape[1] t = numpy.arange(0, T) fin = plot_m[-1] best = sorted[0][-1] alpha = 1.0 / (n // 2) * 0.4 if subsample > 1: t = subsample_data(t, subsample) plot_m = subsample_data(plot_m, subsample) sorted = subsample_data(sorted, subsample) if k == 0: if ylim is None: ymax = min([fin * ylim_scale, sorted[-1, 0], 90]) ymin = numpy.floor(numpy.max(best / ylim_unit - 0.5, 0)) * ylim_unit ymin = 0 ylim = [ymin, numpy.ceil(ymax / ylim_unit) * ylim_unit] else: ylim = ylim # 3: 0 if draw_dist[k]: print('k', k) for i in range(n // 2): ax.fill_between(t, sorted[-1 - i], sorted[i], facecolor=colors2[k], alpha=alpha) for k in range(m)[::-1]: plot_m = numpy.median(data[k], 0) t = numpy.arange(0, T) if subsample > 1: t = subsample_data(t, subsample) plot_m = subsample_data(plot_m, subsample) ax.plot(t, plot_m, lw=1, color=colors[k], ls='-', label=labels[k]) if hline is not None: ax.plot((0, T), (hline, hline), color='gray', ls=':') if vline is not None: ax.plot((vline, vline), (ylim[0], ylim[1]), color='gray', ls=':') ax.legend(loc='upper right') ax.set_xlabel('Iterations') ax.set_ylabel(ylabel) ax.set_xlim([0, T]) ax.set_ylim(ylim) if locator >= 0: ax.yaxis.set_major_locator(MultipleLocator(locator)) ax.grid() plt.savefig(savefile + '.png') plt.savefig(savefile + '.pdf')