plotting.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:analyzefit 作者: wsmorgan 项目源码 文件源码
def scatter(x,y,show_plt=True, x_label=None, y_label=None, label=None,
            title=None,fig=None,ax=None):
    """Make a standard matplotlib style scatter plot.

    Args:
        x (numpy.ndarray): The data for the x-axis.
        y (numpy.ndarray): The data for the y-axis.
        show (bool, optional): True if plot is to be shown.
        x_label (str, optional): The x-axis label.
        y_label (str, optional): The y-axis label.
        label (str, optional): The data trend label.
        title (str, optional): The plot title.
        fig (matplotlib.figure.Figure, optional): An initial figure to add points too.
        ax (matplotlib.axes._subplots.AxesSubplot, optional): A subplot object to plot on.

    Returns:
        fig (matplotlib object): Returns the matplotlib object if show = False.
    """
    if fig is None and ax is None:
        fig = plt.figure()
    elif ax is None:
        fig = fig
    else:
        ax = ax

    if not isinstance(x,np.ndarray): #pragma: no cover
        x = np.array(x)
    if not isinstance(y,np.ndarray): #pragma: no cover
        y = np.array(y)

    if ax is None:
        if label is not None:
            plt.scatter(x,y,label=label)
        else:
            plt.scatter(x,y)

        if x_label is not None:
            plt.xlabel(x_label)
        if y_label is not None:
            plt.ylabel(y_label)
        if title is not None:
            plt.title(title)
    else:
        if label is not None:
            ax.scatter(x,y,label=label)
        else:
            ax.scatter(x,y)

        if x_label is not None:
            ax.set_xlabel(x_label)
        if y_label is not None:
            ax.set_ylabel(y_label)
        if title is not None:
            ax.set_title(title)

        return ax

    if show_plt is True: #pragma: no cover
        plt.show()
    else:
        return fig
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号