Exemple #1
0
  def plotshock(self):
    if self.runshock == False:
      self.shock()

    fig_width = 7
    golden_mean = (np.sqrt(5.) - 1.)/2. 
    fig_height = 5.5
    fig = plt.figure(figsize=(fig_width, fig_height))

    grids = gs.GridSpec(5, 1, figure=fig, hspace=0)
    ax1 = fig.add_subplot(grids[0, 0])
    ax2 = fig.add_subplot(grids[1, 0])
    ax3 = fig.add_subplot(grids[2, 0])
    ax4 = fig.add_subplot(grids[3, 0])
    ax5 = fig.add_subplot(grids[4, 0])

    ax1.plot(self.x_sh, self.dpcdx_sh, label='$\\nabla P_c$')

    ax2.semilogy(self.x_sh, self.sc_sh, label='$\\sigma_c$')

    ax3.plot(self.x_sh, self.fc_sh, 'b', label='$F_c$')
    ax3.plot(self.x_sh, self.fcsteady, 'r--', label='Steady $F_c$')

    ax4.plot(self.x_sh, self.rho_sh, label='$\\rho$')

    ax5.plot(self.x_sh, self.pc_sh, label='$P_c$')

    for axes in fig.axes:
      axes.axvline(self.x_sh[self.istr], linestyle='--', color='grey')
      axes.axvline(self.x_sh[self.ichk], linestyle='--', color='purple')
      axes.margins(x=0)
      if axes != ax2:
        axes.xaxis.set_minor_locator(AutoMinorLocator())
        axes.yaxis.set_minor_locator(AutoMinorLocator())

      if axes != ax4:
        axes.legend(frameon=False, fontsize=10)
      else:
        handles, labels = axes.get_legend_handles_labels()
        handles1, labels1 = handles[0:3], labels[0:3]
        handles2, labels2 = handles[3:-1], labels[3:-1]
        handles3, labels3 = [handles[-1]], [labels[-1]]
        axes.legend(handles1, labels1, frameon=False, loc='upper right', ncol=3, fontsize=12)
        leg2 = lg.Legend(axes, handles2, labels2, frameon=False, loc='upper left', ncol=3, fontsize=12)
        leg3 = lg.Legend(axes, handles3, labels3, frameon=False, loc='lower left', fontsize=12)
        axes.add_artist(leg2)
        axes.add_artist(leg3)

      if axes != ax5:
        axes.set_xticks([])
      else:
        axes.set_xlabel('$x$', fontsize=10)

      for label in (axes.get_xticklabels() + axes.get_yticklabels()):
        label.set_fontsize(10)

      fig.tight_layout()
      
    return fig
Exemple #2
0
    def legend(self, *args, **kwargs):

        if len(args) == 0:
            all_handles = _get_handles(self)
            for ax in self.parasites:
                all_handles.extend(_get_handles(ax))
            handles = []
            labels = []
            for handle in all_handles:
                label = handle.get_label()
                if (label is not None and label != ''
                        and not label.startswith('_')):
                    handles.append(handle)
                    labels.append(label)
            if len(handles) == 0:
                warnings.warn("No labeled objects found. "
                              "Use label='...' kwarg on individual plots.")
                return None

        elif len(args) == 1:
            # LABELS
            labels = args[0]
            handles = [h for h, label in zip(all_handles, labels)]

        elif len(args) == 2:
            if is_string_like(args[1]) or isinstance(args[1], int):
                # LABELS, LOC
                labels, loc = args
                handles = [h for h, label in zip(all_handles, labels)]
                kwargs['loc'] = loc
            else:
                # LINES, LABELS
                handles, labels = args

        elif len(args) == 3:
            # LINES, LABELS, LOC
            handles, labels, loc = args
            kwargs['loc'] = loc
        else:
            raise TypeError('Invalid arguments to legend')

        handles = cbook.flatten(handles)
        self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
        return self.legend_
        def startReading(event):
            self.startButton.color = 'g'
            self.startButton.active = False
            self.stopButton.active = True
            self.pauseButton.active = True

            self.pipe.send(('s', None, None))
            #Initialize three lines for three channels
            self.line1 = lines.Line2D([], [], color='r')
            self.line2 = lines.Line2D([], [], color='g')
            self.line3 = lines.Line2D([], [], color='b')

            self.ax.add_line(self.line1)
            self.ax.add_line(self.line2)
            self.ax.add_line(self.line3)

            legend1 = lgnd.Legend(self.ax, [self.line1, self.line2, self.line3], \
                ['Channel 1', 'Channel 2', 'Channel 3'])
            self.ax.add_artist(legend1)
            self.ax.set_ylim([0, 10])

            self.timer = self.fig.canvas.new_timer(interval=100)
            self.timer.add_callback(self.call_back)
            self.timer.start()
Exemple #4
0
ax = fig.add_subplot(111)
arr = [1, 2, 3]
line = ax.plot(arr)

ax2 = fig.add_subplot(111)
arr2 = [2, 3, 4]
line2 = ax2.plot(arr2)

ax3 = fig.add_subplot(111)
arr3 = [3, 4, 5]
line3 = ax3.plot(arr3)

# 1つ目の凡例生成
leg1 = ax.legend(line, ["1"], ncol=1)
# 2つ目の凡例を生成
leg2 = lgd.Legend(ax2, line2, ["2"], ncol=2)
# 3つ目の凡例を生成
leg3 = lgd.Legend(ax3, line3, ["3"], ncol=3)

# 1つ目の凡例に2つ目の凡例を追加
leg1._legend_box._children.append(leg2._legend_box._children[1])
# 1つ目の凡例に3つ目の凡例を追加
leg1._legend_box._children.append(leg3._legend_box._children[1])
# デフォルト中央寄せのため、左寄せ
leg1._legend_box.align = "left"

fig.show()

# In[ ]:
#Legend for clinical matrix
clinical_legend = fig.add_subplot(gs[1, 1])
labels1 = ['N/A', '1', '2', '3', '4', '5']
handles1 = [
    Patch(color='#ededed', linewidth=0),
    Patch(color='#dcd6ff', linewidth=0),
    Patch(color='#a699ff', linewidth=0),
    Patch(color='#7b68fc', linewidth=0),
    Patch(color='#422fc2', linewidth=0),
    Patch(color='#0a004d', linewidth=0)
]
legend1 = legend.Legend(clinical_legend,
                        handles=handles1,
                        labels=labels1,
                        ncol=7,
                        loc=(0, 0),
                        columnspacing=None,
                        handlelength=0.8,
                        frameon=False,
                        fontsize=8)

labels2 = ['PB', 'RP', 'MLN', 'cfDNA', 'MB']
handles2 = [
    Patch(color='#667bb3', linewidth=0),
    Patch(color='#f7d58b', linewidth=0),
    Patch(color='#aae6bb', linewidth=0),
    Patch(color='#994545', linewidth=0),
    Patch(color='#dea2e8', linewidth=0)
]
legend2 = legend.Legend(clinical_legend,
                        handles=handles2,