通过循环或列表的方式,可以为不同的数据点设置不同的标记样式: markers = ['o','s','^','*','d']fori, markerinenumerate(markers): plt.plot(x[i], y[i], marker=marker, markersize=12, label=f"Point{i+1}") plt.legend() plt.title("不同点的标记样式") plt.show() 为数据点添加标签...
matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None, plotnonfinite=False, data=None, **kwargs) 属性参数意义 坐标 x,y 输入点列的数组,长度都是size 点大小 s 点的直径数组,默认直径20...
importmatplotlib.pyplotaspltimportnumpyasnp markers=['o','s','^','v','D','*','+','x']x=np.arange(len(markers))y=np.random.rand(len(markers))plt.figure(figsize=(12,6))fori,markerinenumerate(markers):plt.scatter(x[i],y[i],marker=marker,s=200,label=f'Marker:{marker}')plt....
3、matplotlib.axes.Axes.scatter法绘制散点图 importmatplotlib.pyplotaspltimportnumpyasnpimportpandasaspdfrompandasimportSeries,DataFrame#数据准备fromsklearnimportdatasetsiris=datasets.load_iris()x,y=iris.data,iris.targetpd_iris=pd.DataFrame(np.hstack((x,y.reshape(150,1))),columns=['sepal length(cm...
散点图是使用标记的最常见场景之一。我们可以使用scatter()函数来创建散点图,并自定义标记的各种属性。以下是一个示例: importmatplotlib.pyplotaspltimportnumpyasnp np.random.seed(42)x=np.random.rand(50)y=np.random.rand(50)colors=np.random.rand(50)sizes=1000*np.random.rand(50)plt.figure(figsize=...
Markers (scatter plot) - 标记 Major tick - 主刻度 Minor tick - 次刻度 Axes - 轴 Spines - 脊 这些基础概念十分有用,希望大家能记住其作用及对应的英文。如果遇到更复杂的需求,可以直接在官网文档中进行查询。 环境 Python 3.7.3 Matplotlib 3.1.3 常用链接 颜色Colors: - Choosing Colormaps in ...
import matplotlib.pyplot as plt # 创建一个数据集,X有两个特征,y={-1,1} X, y = make_blobs(n_samples=500, centers=2, random_state=6) y[y == 0] = -1 plt.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap=plt.cm.Paired) ...
importmatplotlib.pyplotasplt plt.scatter(xArr,yArr)plt.show() 2、设置散点的大小 代码语言:javascript 代码运行次数:0 运行 AI代码解释 plt.scatter(x,y,s) 通过修改s的值即可,比如设置为5。 3、更改散点的颜色 代码语言:javascript 代码运行次数:0 ...
Basic: Line plots, scatter plots, bar charts, pie charts Advanced: Contour plots, heatmaps, 3D surface plots Statistical: Box plots, histograms, error bars 2 定制化功能 2 Customization 多子图布局:`subplots()` 创建复杂布局 样式控制:线型、颜色、标记、透明度 注释文本:箭头、文本标签、...
You can set your own color for each scatter plot with the color or the c argument:Example Set your own color of the markers: import matplotlib.pyplot as pltimport numpy as npx = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6]) y = np.array([99,86,87,88,111,86,103,87,94,...