コード例 #1
0
ファイル: sketchy.py プロジェクト: Wytamma/sketchy
    def plot_preference_score(
        self,
        feature_data: pandas.DataFrame,
        ax: plt.axes = None
    ) -> None:

        p3 = sns.lineplot(
            data=feature_data, x='read', y='score',
            ax=ax, color='#333333', ci=None, estimator=None
        )

        ax.axhline(
            y=self.preference_threshold, linewidth=1, linestyle='--', color='black'
        )

        # Legend and labels
        p3.tick_params(labelsize=6)
        p3.set_xlabel('\nReads', fontsize=9)
        p3.set_ylabel('Preference score\n', fontsize=9)
コード例 #2
0
    def _plot_analytical(self,
                         ax: plt.axes,
                         sym_func,
                         title: str = "",
                         maxmin_hline: bool = True,
                         xunits: str = "",
                         yunits: str = "",
                         xlabel: str = "",
                         ylabel: str = "",
                         color=None,
                         inverted=False):
        """
        Auxiliary function for plotting a sympy.Piecewise analytical function.

        :param ax: a matplotlib.Axes object where the data is to be plotted.
        :param x_vec: array-like, support where the provided symbolic function will be plotted
        :param sym_func: symbolic function using the variable x
        :param title: title to show above the plot, optional
        :param maxmin_hline: when set to False, the extreme values of the function are not displayed
        :param xunits: str, physical unit to be used for the x-axis. Example: "m"
        :param yunits: str, physical unit to be used for the y-axis. Example: "kN"
        :param xlabel: str, physical variable displayed on the x-axis. Example: "Length"
        :param ylabel: str, physical variable displayed on the y-axis. Example: "Shear force"
        :param color: color to be used for the shaded area of the plot. No shading if not provided
        :return: a matplotlib.Axes object representing the plotted data.

        """
        x_vec = np.linspace(self._x0, self._x1,
                            min(int((self.length) * 1000 + 1), 1e4))
        y_lam = lambdify(x, sym_func, "numpy")
        y_vec = np.array([y_lam(t) for t in x_vec])

        if inverted:
            y_vec *= -1

        if color:
            a, b = x_vec[0], x_vec[-1]
            verts = [(a, 0)] + list(zip(x_vec, y_vec)) + [(b, 0)]
            poly = Polygon(verts, facecolor=color, edgecolor='0.5', alpha=0.4)
            ax.add_patch(poly)

        if maxmin_hline:
            tol = 1e-3

            if abs(max(y_vec)) > tol:
                ax.axhline(y=max(y_vec), linestyle='--', color="g", alpha=0.5)
                max_idx = y_vec.argmax()
                plt.annotate('${:0.1f}'.format(
                    y_vec[max_idx] *
                    (1 - 2 * inverted)).rstrip('0').rstrip('.') +
                             " $ {}".format(yunits),
                             xy=(x_vec[max_idx], y_vec[max_idx]),
                             xytext=(8, 0),
                             xycoords=('data', 'data'),
                             textcoords='offset points',
                             size=12)

            if abs(min(y_vec)) > tol:
                ax.axhline(y=min(y_vec), linestyle='--', color="g", alpha=0.5)
                min_idx = y_vec.argmin()
                plt.annotate('${:0.1f}'.format(
                    y_vec[min_idx] *
                    (1 - 2 * inverted)).rstrip('0').rstrip('.') +
                             " $ {}".format(yunits),
                             xy=(x_vec[min_idx], y_vec[min_idx]),
                             xytext=(8, 0),
                             xycoords=('data', 'data'),
                             textcoords='offset points',
                             size=12)

        xspan = x_vec.max() - x_vec.min()
        ax.set_xlim([x_vec.min() - 0.01 * xspan, x_vec.max() + 0.01 * xspan])
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)

        if title:
            ax.set_title(title)

        if xlabel or xunits:
            ax.set_xlabel('{} [{}]'.format(xlabel, xunits))

        if ylabel or yunits:
            ax.set_ylabel("{} [{}]".format(ylabel, yunits))

        return ax