Exemplo n.º 1
0
def hist2d_scatter(x,
                   y,
                   bg_x,
                   bg_y,
                   axis: matplotlib.axes.Axes,
                   dataset_name: str,
                   normalize=True,
                   marker_color: str = 'k',
                   bins=300,
                   colormap_name: str = 'jet',
                   color_bar=False,
                   hist2dkw={},
                   scatterkw={}):
    """Plots 2D histogram with two parameters (e.g. BxGSM and ByGSM).
    x, y (array_like): Values of the TPAs for the parameter that will be plotted on the x- or y-axis.
                       This data will correspond to the dots in the plot.
    bg_x, bg_y (array_like): Values of the IMF over the period of the dataset.
                             These will form the background (colored tiles) of the plot
    """
    colormap = cm.get_cmap(colormap_name)
    axis.axhline(0, color='grey', zorder=1)
    axis.axvline(0, color='grey', zorder=1)
    omit_index = np.isnan(x) | np.isnan(y)
    x = x[~omit_index]
    y = y[~omit_index]
    bg_omit_index = np.isnan(bg_x) | np.isnan(bg_y)
    bg_x = bg_x[~bg_omit_index]
    bg_y = bg_y[~bg_omit_index]
    counts, xedges, yedges, im = axis.hist2d(bg_x,
                                             bg_y,
                                             bins=bins,
                                             cmap=colormap,
                                             density=normalize,
                                             zorder=0,
                                             **hist2dkw)

    if color_bar:
        cbar = plt.colorbar(im, ax=axis)
        cbar.set_label('IMF probability distribution',
                       rotation=270,
                       labelpad=10)

    scatter = axis.scatter(x,
                           y,
                           s=30,
                           marker='P',
                           edgecolors='w',
                           linewidth=0.5,
                           label=dataset_name,
                           c=marker_color[~omit_index] if isinstance(
                               marker_color, np.ndarray) else marker_color,
                           zorder=2,
                           **scatterkw)

    axis.set_facecolor(colormap(0))
    axis.legend(loc='upper left')
    return scatter, counts, xedges, yedges, im
Exemplo n.º 2
0
 def plot(self,
          ax: matplotlib.axes.Axes,
          back_color: utils.Color = "white") -> None:
     """
     Draw plot on ax
     back_color: background color for plot
     """
     ax.ticklabel_format(axis="y", scilimits=[0, 0])
     ax.set_facecolor(back_color)
     ax.set_title(f"{self.title}\n{self.group_name}")