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
评论列表
文章目录