Пример #1
0
 def to_latex(self, var="T"):
     lx = "\n"\
          r"\begin{equation}"                   + \
          f"\n   {var} = {sp.latex(self.matrix)}\n" + \
          r"\end{equation}"
     print_color(lx, "blue")
     return lx
Пример #2
0
def get_available_fonts():
    """
    :return: Print all available fonts
    """
    flist = matplotlib.font_manager.get_fontconfig_fonts()
    names = [
        matplotlib.font_manager.FontProperties(fname=fname).get_name()
        for fname in flist
    ]

    print_color("Matplotlib: available fonts", "blue")
    for i in range(len(names)):
        n = f"{i+1}"
        numeral = n + "." + " " * (4 - len(n))
        print(numeral + '"' + names[i] + '"')
Пример #3
0
    def method_lighting(self):
        ls = LightSource(270, 45)

        if not isinstance(self.color, type(None)):
            if isinstance(self.cmap_lighting, type(None)):
                try:
                    cmap = difflib.get_close_matches(self.color,
                                                     self.plt.colormaps())[0]
                    print_color(
                        f'You have selected the solid _color_ "{self.color}" for your surface, and set _lighting_ as True\n\n'
                        f'   The search for Matplotlib colormaps similar to "{self.color}" has resulted in: \n',
                        "blue")
                    print(f'       "{cmap}"\n')
                    print_color(
                        '   Specify a custom colormap for the lighting function with the _cmap_lighting_ attribute.\n'
                        '   NOTE: This will overrule your monochrome color, however. Set _lighting_ to False if this is undesired.',
                        "blue")
                except IndexError:
                    cmap = "Greys"
                    print_color(
                        f'You have selected the solid _color_ "{self.color}" for your surface, and set _lighting_ as True\n\n'
                        f'   The search for Matplotlib colormaps similar to "{self.color}" has failed. Reverting to\n',
                        "red")
                    print(f'       "{cmap}"\n')
                    print_color(
                        '   Specify a custom colormap for the lighting function with the _cmap_lighting_ attribute.\n'
                        '   NOTE: This will overrule your monochrome color, however. Set _lighting_ to False if this is undesired.',
                        "red")
            else:
                cmap = self.cmap_lighting
        else:
            cmap = self.cmap_lighting if not isinstance(
                self.cmap_lighting, type(None)) else self.cmap

        rgb = ls.shade(self.z,
                       cmap=cm.get_cmap(cmap),
                       vert_exag=0.1,
                       blend_mode='soft')

        return rgb
Пример #4
0
    def n_pane_comparison(cls,
                          t,
                          y,
                          axis_labels=None,
                          legend_labels=None,
                          filename=None,
                          where_does_this_go=None,
                          zorders=None,
                          colors=None,
                          alphas=None,
                          save=False,
                          show=True):

        t, y = to_ndarrays(t, y)
        t = cls.comparison_input_match(t, y)

        zorders = if_none(zorders, np.arange(len(y) + 1, 0, -1))
        colors = if_none(colors, [one()[n] for n in range(len(y))])
        print(colors)
        alphas = if_none(alphas, np.ones(len(y)))

        fig = figure((5 * len(y), 3.5))

        for i in range(len(y)):
            ax_transient = plt.subplot2grid((1, len(y)), (0, i),
                                            rowspan=1,
                                            colspan=1)
            if i < (len(y) - 1):
                cls.comparison(
                    [t[i][n] for n in range(len(y[1]))],
                    [y[i][n] for n in range(len(y[1]))],
                    ax_transient,
                    fig,
                    y_label=axis_labels[i]
                    if not isinstance(axis_labels, type(None)) else None,
                    zorders=zorders,
                    colors=colors,
                    alphas=alphas,
                )
            else:
                cls.comparison(
                    [t[i][n] for n in range(len(y[1]))],
                    [y[i][n] for n in range(len(y[1]))],
                    ax_transient,
                    fig,
                    y_label=axis_labels[i]
                    if not isinstance(axis_labels, type(None)) else None,
                    zorders=zorders,
                    colors=colors,
                    alphas=alphas,
                    plot_labels=legend_labels,
                    legend=True
                    if not isinstance(legend_labels, type(None)) else False,
                    legend_loc=(0.875, 0.425))

        plt.subplots_adjust(left=0.1, right=0.85, wspace=0.6, hspace=0.35)
        legend = (c for c in ax_transient.get_children()
                  if isinstance(c, mpl.legend.Legend))

        if save:
            filename = input("Filename:") if isinstance(filename, type(None)) \
                else filename
            where_does_this_go = input("Destination directory:") if isinstance(where_does_this_go, type(None)) \
                else where_does_this_go
            try:
                plt.savefig(
                    f"{where_does_this_go}/{filename}.pdf",
                    bbox_extra_artists=legend,
                )
            except FileNotFoundError:
                print_color(
                    "Destination directory does not exist. Destination directory:",
                    "blue")
                where_does_this_go = input()
                plt.savefig(
                    f"{where_does_this_go}/{filename}.pdf",
                    bbox_extra_artists=legend,
                )
        if show:
            plt.show()
Пример #5
0
    def method_cb(self):
        if self.color_bar is True:
            if isinstance(self.norm, type(None)):
                return print_color(
                    "No norm selected for colorbar. Set norm=<parameter of choice>",
                    "grey")

            # Obtain and apply limits
            if isinstance(self.cb_vmin, type(None)):
                self.cb_vmin = self.norm.min()
            if isinstance(self.cb_vmax, type(None)):
                self.cb_vmax = self.norm.max()
            self.graph.set_clim([self.cb_vmin, self.cb_vmax])

            # Normalization
            locator = np.linspace(self.cb_vmin, self.cb_vmax,
                                  self.cb_tick_number)

            # Colorbar
            cbar = self.fig.colorbar(
                self.graph,
                ax=self.ax,
                orientation=self.cb_orientation,
                shrink=self.shrink,
                ticks=locator,
                boundaries=locator if self.cb_hard_bounds is True else None,
                spacing='proportional',
                extend=self.extend,
                format='%.' + str(self.tick_ndecimals) + 'f',
                pad=self.cb_pad,
            )

            # Ticks
            #   Locator
            cbar.locator = locator
            #   Direction
            cbar.ax.tick_params(axis='y', direction='out')
            #   Tick label pad and size
            cbar.ax.yaxis.set_tick_params(pad=self.cb_axis_labelpad,
                                          labelsize=self.cb_ticklabelsize)

            # Title
            if self.cb_orientation == 'vertical':
                if not isinstance(
                        self.cb_title, type(None)
                ) and self.cb_y_title is False and self.cb_top_title is False:
                    print(
                        'Input colorbar title location with booleans: cb_y_title=True or cb_top_title=True'
                    )
                if self.cb_y_title is True:
                    cbar.ax.set_ylabel(self.cb_title,
                                       rotation=self.cb_title_rotation,
                                       labelpad=self.cb_ytitle_labelpad)
                    text = cbar.ax.yaxis.label
                    font = mpl.font_manager.FontProperties(
                        family=self.font,
                        style=self.cb_title_style,
                        size=self.cb_title_size,
                        weight=self.cb_title_weight)
                    text.set_font_properties(font)
                if self.cb_top_title is True:
                    cbar.ax.set_title(self.cb_title,
                                      rotation=self.cb_title_rotation,
                                      fontdict={
                                          'verticalalignment': 'baseline',
                                          'horizontalalignment': 'left'
                                      },
                                      pad=self.cb_top_title_pad)
                    cbar.ax.title.set_position(
                        (self.x_cb_top_title, self.cb_top_title_y))
                    text = cbar.ax.title
                    font = mpl.font_manager.FontProperties(
                        family=self.font,
                        style=self.cb_title_style,
                        weight=self.cb_title_weight,
                        size=self.cb_title_size)
                    text.set_font_properties(font)
            elif self.cb_orientation == 'horizontal':
                cbar.ax.set_xlabel(self.cb_title,
                                   rotation=self.cb_title_rotation,
                                   labelpad=self.cb_ytitle_labelpad)
                text = cbar.ax.xaxis.label
                font = mpl.font_manager.FontProperties(
                    family=self.font,
                    style=self.cb_title_style,
                    size=self.cb_title_size,
                    weight=self.cb_title_weight)
                text.set_font_properties(font)

            # Outline
            cbar.outline.set_edgecolor(self.workspace_color2)
            cbar.outline.set_linewidth(self.cb_outline_width)
Пример #6
0
 def type_mismatch(self, other):
     if not self.suppress:
         print_color(f"===================================================",
                     "red")
         print_color(f"Warning: Type mismatch between multiplied matrices:",
                     "red")
         print_color(f"{type(self.matrix)}", "blue")
         print(f"{self.__repr__()}")
         print_color(f"{type(other.matrix)}", "blue")
         print(f"{other.matrix}")
         print_color(f"Proceeding with matrix multiplication", "red")
         print_color(f"===================================================",
                     "red")
Пример #7
0
 def lambdification_info(self, params, *args):
     print_color(f"\nLambdifying rotation matrix with parameters\n", "blue")
     print("===========================================")
     for i in list(zip(params, [*args])):
         print(tuple_to_equal(str(i)))
     print("===========================================")
Пример #8
0
    def n_pane_single(cls,
                      x,
                      y,
                      labels=None,
                      legend_labels=None,
                      filename=None,
                      where_does_this_go=None,
                      **kwargs):

        # Regular defaults
        backend = kwargs.pop('backend', None)  # Setup
        legend_loc = kwargs.pop('legend_loc', (0.875, 0.55))  # Legend
        show = kwargs.pop('show', False)  # Display
        save = kwargs.pop('save', False)
        legend = kwargs.pop('legend',
                            True if not isinstance(legend_labels, type(None))
                            else True)  # Legend

        # Figure setup
        fig = figure((5 * len(y), 3.5), backend=backend)
        import matplotlib.pyplot as plt

        # Plot
        for i in range(len(y)):
            ax_transient = plt.subplot2grid((1, len(y)), (0, i),
                                            rowspan=1,
                                            colspan=1)
            if i < (len(y) - 1):
                line(x=x,
                     y=y[i],
                     color=one()[i],
                     ax=ax_transient,
                     fig=fig,
                     y_label=labels[i]
                     if not isinstance(labels, type(None)) else None,
                     plot_label=legend_labels[i]
                     if not isinstance(legend_labels, type(None)) else None,
                     backend=backend)
            else:
                line(x=x,
                     y=y[i],
                     color=one()[i],
                     ax=ax_transient,
                     fig=fig,
                     y_label=labels[i]
                     if not isinstance(labels, type(None)) else None,
                     legend=True
                     if not isinstance(legend_labels, type(None)) else False,
                     plot_label=legend_labels[i]
                     if not isinstance(legend_labels, type(None)) else None,
                     legend_loc=legend_loc,
                     backend=backend,
                     **kwargs)

        plt.subplots_adjust(left=0.1, right=0.85, wspace=0.6, hspace=0.35)

        if not isinstance(filename, type(None)) and not isinstance(
                where_does_this_go, type(None)):
            plt.savefig(f"{where_does_this_go}/{filename}.pdf")
            plt.show()
        if show:
            plt.show()

        if save:
            filename = input("Filename:") if isinstance(filename, type(None)) \
                else filename
            where_does_this_go = input("Destination directory:") if isinstance(where_does_this_go, type(None)) \
                else where_does_this_go
            try:
                plt.savefig(
                    f"{where_does_this_go}/{filename}.pdf",
                    bbox_extra_artists=legend,
                )
            except FileNotFoundError:
                print_color(
                    "Destination directory does not exist. Destination directory:",
                    "blue")
                where_does_this_go = input()
                plt.savefig(
                    f"{where_does_this_go}/{filename}.pdf",
                    bbox_extra_artists=legend,
                )
        if show:
            plt.show()
Пример #9
0
    def n_pane_comparison(cls,
                          t,
                          y,
                          axis_labels=None,
                          legend_labels=None,
                          zorders=None,
                          colors=None,
                          alphas=None,
                          filename=None,
                          where_does_this_go=None,
                          **kwargs):

        # Input check
        t, y = lists_to_ndarrays(t, y)
        t = cls.comparison_input_match(t, y)

        # Special parameters
        zorders = if_none(zorders, np.arange(len(y) + 1, 0, -1))
        colors = if_none(colors, [one()[n] for n in range(len(y))])
        alphas = if_none(alphas, np.ones(len(y)))

        # Regular defaults
        backend = kwargs.pop('backend', None)  # Setup
        legend_loc = kwargs.pop('legend_loc', (0.875, 0.55))  # Legend
        show = kwargs.pop('show', False)  # Display
        save = kwargs.pop('save', False)

        # Figure setup
        fig = figure((5 * len(y), 3.5), backend=backend)
        import matplotlib.pyplot as plt

        # Plot
        for i in range(len(y)):
            ax_transient = plt.subplot2grid((1, len(y)), (0, i),
                                            rowspan=1,
                                            colspan=1)
            if i < (len(y) - 1):
                cls.comparison(
                    [t[i][n] for n in range(len(y[1]))],
                    [y[i][n] for n in range(len(y[1]))],
                    ax=ax_transient,
                    fig=fig,
                    backend=backend,
                    y_label=axis_labels[i]
                    if not isinstance(axis_labels, type(None)) else None,
                    zorders=zorders,
                    colors=colors,
                    alphas=alphas,
                    legend=False)
            else:
                cls.comparison(
                    [t[i][n] for n in range(len(y[1]))],
                    [y[i][n] for n in range(len(y[1]))],
                    ax=ax_transient,
                    fig=fig,
                    backend=backend,
                    y_label=axis_labels[i]
                    if not isinstance(axis_labels, type(None)) else None,
                    zorders=zorders,
                    colors=colors,
                    alphas=alphas,
                    plot_labels=legend_labels,
                    legend=True
                    if not isinstance(legend_labels, type(None)) else False,
                    legend_loc=legend_loc,
                    **kwargs)

        plt.subplots_adjust(left=0.1, right=0.85, wspace=0.6, hspace=0.35)
        legend = (c for c in ax_transient.get_children()
                  if isinstance(c, mpl.legend.Legend))

        if save:
            filename = input("Filename:") if isinstance(filename, type(None)) \
                else filename
            where_does_this_go = input("Destination directory:") if isinstance(where_does_this_go, type(None)) \
                else where_does_this_go
            try:
                plt.savefig(
                    f"{where_does_this_go}/{filename}.pdf",
                    bbox_extra_artists=legend,
                )
            except FileNotFoundError:
                print_color(
                    "Destination directory does not exist. Destination directory:",
                    "blue")
                where_does_this_go = input()
                plt.savefig(
                    f"{where_does_this_go}/{filename}.pdf",
                    bbox_extra_artists=legend,
                )
        if show:
            plt.show()