通过循环或列表的方式,可以为不同的数据点设置不同的标记样式: 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("不同点的标记样
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....
我们可以使用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=(10,8))scatter=plt.scatter(x,y,...
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...
matplotlib.pyplot.scatter 1、scatter函数原型 2、其中散点的形状参数marker如下: 3、其中颜色参数c如下: 4、基本的使用方法如下: #导入必要的模块 import numpyasnp import matplotlib.pyplotasplt #产生测试数据 x= np.arange(1,10) y=x fig=plt.figure() ...
Markers (scatter plot) - 标记 Major tick - 主刻度 Minor tick - 次刻度 Axes - 轴 Spines - 脊 这些基础概念十分有用,希望大家能记住其作用及对应的英文。如果遇到更复杂的需求,可以直接在官网文档中进行查询。 环境 Python 3.7.3 Matplotlib 3.1.3 常用链接 颜色Colors: - Choosing Colormaps in ...
importmatplotlib.pyplotasplt plt.scatter(xArr,yArr)plt.show() 2、设置散点的大小 代码语言:javascript 代码运行次数:0 运行 AI代码解释 plt.scatter(x,y,s) 通过修改s的值即可,比如设置为5。 3、更改散点的颜色 代码语言:javascript 代码运行次数:0 ...
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) ...
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,...
Matplotlib scatter marker multiple plot What happens if we want to draw multiple scatter markers plot in the same figure. Let’s understand the concept with the help of an example: # Import Librariesimport matplotlib.pyplot as plt import numpy as np# Plot datax = np.array([5,7,8,7]) ...