import matplotlib.pyplot as plt
import numpy as np
# 生成随机数据
np.random.seed(0)
x = np.random.rand(50)
y = np.random.rand(50)
colors = np.random.rand(50)
area = np.pi * (15 * np.random.rand(50))**2 # 点的大小
# 创建散点图
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
# 添加标题和标签
plt.title('Scatter Plot Example')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
# 显示图形
plt.show()
matplotlib.pyplot
是一个常用的绘图库,plt.scatter()
用于绘制散点图。numpy
用于生成随机数据。x
和 y
是散点图的坐标,colors
控制每个点的颜色,area
控制每个点的大小。alpha
参数控制点的透明度。plt.title()
、plt.xlabel()
和 plt.ylabel()
分别用于设置图表的标题和轴标签。plt.show()
来显示图形。上一篇:python中的pip
下一篇:在线python运行
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站