Exemplo n.º 1
0
    def plot_1d_quiver(self,
                       fig,
                       ax,
                       time,
                       u,
                       v,
                       title='',
                       ylabel='',
                       title_font={},
                       axis_font={},
                       tick_font={},
                       legend_title="Magnitude",
                       start=None,
                       end=None,
                       **kwargs):

        if not title_font:
            title_font = title_font_default
        if not axis_font:
            axis_font = axis_font_default
        # Plot quiver
        magnitude = (u**2 + v**2)**0.5
        maxmag = max(magnitude)
        ax.set_ylim(-maxmag, maxmag)
        dx = time[-1] - time[0]

        if start and end:
            ax.set_xlim(start - 0.05 * dx, end + 0.05 * dx)
        else:
            ax.set_xlim(time[0] - 0.05 * dx, time[-1] + 0.05 * dx)
        # ax.fill_between(time, magnitude, 0, color='k', alpha=0.1)

        # # Fake 'box' to be able to insert a legend for 'Magnitude'
        # p = ax.add_patch(plt.Rectangle((1, 1), 1, 1, fc='k', alpha=0.1))
        # leg1 = ax.legend([p], [legend_title], loc='lower right')
        # leg1._drawFrame = False

        # # 1D Quiver plot
        q = ax.quiver(time, 0, u, v, **kwargs)
        plt.quiverkey(q,
                      0.2,
                      0.05,
                      0.2,
                      r'$0.2 \frac{m}{s}$',
                      labelpos='W',
                      fontproperties={'weight': 'bold'})

        ax.xaxis_date()
        date_list = mdates.num2date(time)
        self.get_time_label(ax, date_list)
        fig.autofmt_xdate()

        if ylabel:
            ax.set_ylabel(ylabel.replace("_", " "), labelpad=20, **axis_font)
        if tick_font:
            ax.tick_params(**tick_font)
        ax.set_title(title.replace("_", " "), **title_font)
        plt.tight_layout()
Exemplo n.º 2
0
    def plot_1d_quiver(self, fig, ax, time, u, v, title='', ylabel='',
                       title_font={}, axis_font={}, tick_font={}, key_units='m/s',
                       legend_title="Magnitude", start=None, end=None, **kwargs):

        if not title_font:
            title_font = title_font_default
        if not axis_font:
            axis_font = axis_font_default
        # Plot quiver
        magnitude = (u**2 + v**2)**0.5
        maxmag = max(magnitude)
        ax.set_ylim(-maxmag, maxmag)
        dx = time[-1] - time[0]

        if start and end:
            ax.set_xlim(start - 0.05 * dx, end + 0.05 * dx)
        else:
            ax.set_xlim(time[0] - 0.05 * dx, time[-1] + 0.05 * dx)
        # ax.fill_between(time, magnitude, 0, color='k', alpha=0.1)

        # # Fake 'box' to be able to insert a legend for 'Magnitude'
        # p = ax.add_patch(plt.Rectangle((1, 1), 1, 1, fc='k', alpha=0.1))
        # leg1 = ax.legend([p], [legend_title], loc='lower right')
        # leg1._drawFrame = False
        mean_val = np.mean(magnitude)
        # Quick conversion of most popular key_units
        if key_units == 'm s-1':
            key_units = 'm/s'
        key_str = '{0:.2f} {1}'.format(mean_val, key_units)

        # 1D Quiver plot
        q = ax.quiver(time, 0, u, v, **kwargs)
        plt.quiverkey(q, 0.1, 0.05, mean_val,
                      key_str,
                      labelpos='W',
                      fontproperties={'weight': 'light',
                                      'style': 'italic',
                                      'size': 'small',
                                      'stretch': 'condensed'})

        ax.xaxis_date()
        date_list = mdates.num2date(time)
        self.get_time_label(ax, date_list)
        fig.autofmt_xdate()

        if ylabel:
            ax.set_ylabel(ylabel.replace("_", " "), labelpad=20, **axis_font)
        if tick_font:
            ax.tick_params(**tick_font)
        ax.set_title(title.replace("_", " "), **title_font)
        plt.tight_layout()
Exemplo n.º 3
0
    def plot_1d_quiver(self, fig, ax, time, u, v, title='', ylabel='',
                       title_font={}, axis_font={}, tick_font={},
                       legend_title="Magnitude", start=None, end=None, **kwargs):

        if not title_font:
            title_font = title_font_default
        if not axis_font:
            axis_font = axis_font_default
        # Plot quiver
        magnitude = (u**2 + v**2)**0.5
        maxmag = max(magnitude)
        ax.set_ylim(-maxmag, maxmag)
        dx = time[-1] - time[0]

        if start and end:
            ax.set_xlim(start - 0.05 * dx, end + 0.05 * dx)
        else:
            ax.set_xlim(time[0] - 0.05 * dx, time[-1] + 0.05 * dx)
        # ax.fill_between(time, magnitude, 0, color='k', alpha=0.1)

        # # Fake 'box' to be able to insert a legend for 'Magnitude'
        # p = ax.add_patch(plt.Rectangle((1, 1), 1, 1, fc='k', alpha=0.1))
        # leg1 = ax.legend([p], [legend_title], loc='lower right')
        # leg1._drawFrame = False

        # # 1D Quiver plot
        q = ax.quiver(time, 0, u, v, **kwargs)
        plt.quiverkey(q, 0.2, 0.05, 0.2,
                      r'$0.2 \frac{m}{s}$',
                      labelpos='W',
                      fontproperties={'weight': 'bold'})

        ax.xaxis_date()
        date_list = mdates.num2date(time)
        self.get_time_label(ax, date_list)
        fig.autofmt_xdate()

        if ylabel:
            ax.set_ylabel(ylabel.replace("_", " "), labelpad=20, **axis_font)
        if tick_font:
            ax.tick_params(**tick_font)
        ax.set_title(title.replace("_", " "), **title_font)
        plt.tight_layout()