人工智能基础-matplotlib基础

绘制图形

python 复制代码
import numpy as np 
x = np.linspace(0, 10, 100)
y = np.sin(x)
import matplotlib as mpl
import matplotlib.pyplot as plt
plt.plot(x, y)
plt.show()

绘制多条曲线

python 复制代码
siny = y.copy()
cosy = np.cos(x)
plt.plot(x, siny)
plt.plot(x, cosy)
plt.show()

设置线条颜色

python 复制代码
plt.plot(x, siny)
plt.plot(x, cosy, color="red")
plt.show()

设置线条样式

python 复制代码
plt.plot(x, siny)
plt.plot(x, cosy, color="red", linestyle="--")
plt.show()

设置坐标系

python 复制代码
plt.plot(x, siny)
plt.plot(x, cosy, color="red", linestyle="--")
plt.xlim(-5, 15)
plt.ylim(0, 1)
plt.show()
python 复制代码
plt.plot(x, siny)
plt.plot(x, cosy, color="red", linestyle="--")
plt.axis([-1, 11, -2, 2])
plt.show()
python 复制代码
plt.plot(x, siny)
plt.plot(x, cosy, color="red", linestyle="--")
plt.xlabel("x axis")
plt.ylabel("y value")
plt.show()

设置图示

python 复制代码
plt.plot(x, siny, label="sin(x)")
plt.plot(x, cosy, color="red", linestyle="--", label="cos(x)")
plt.xlabel("x axis")
plt.ylabel("y value")
plt.legend()
plt.show()

设置标题

python 复制代码
plt.plot(x, siny, label="sin(x)")
plt.plot(x, cosy, color="red", linestyle="--", label="cos(x)")
plt.xlabel("x axis")
plt.ylabel("y value")
plt.legend()
plt.title("Welcome to matplotlib world!")
plt.show()

散点图

python 复制代码
plt.scatter(x, siny)
plt.show()
python 复制代码
plt.scatter(x, siny)
plt.scatter(x, cosy, color="red")
plt.show()
python 复制代码
x = np.random.normal(0, 1, 10000)
y = np.random.normal(0, 1, 10000)

plt.scatter(x, y, alpha=0.1)
plt.show()
相关推荐
飞哥数智坊1 小时前
从CodeBuddy翻车到MasterGo救场,我的小程序UI终于焕然一新
人工智能
AKAMAI3 小时前
跳过复杂环节:Akamai应用平台让Kubernetes生产就绪——现已正式发布
人工智能·云原生·云计算
新智元5 小时前
阿里王牌 Agent 横扫 SOTA,全栈开源力压 OpenAI!博士级难题一键搞定
人工智能·openai
新智元5 小时前
刚刚,OpenAI/Gemini 共斩 ICPC 2025 金牌!OpenAI 满分碾压横扫全场
人工智能·openai
机器之心5 小时前
OneSearch,揭开快手电商搜索「一步到位」的秘技
人工智能·openai
阿里云大数据AI技术5 小时前
2025云栖大会·大数据AI参会攻略请查收!
大数据·人工智能
YourKing6 小时前
yolov11n.onnx格式模型转换与图像推理
人工智能
sans_6 小时前
NCCL的用户缓冲区注册
人工智能
sans_6 小时前
三种视角下的Symmetric Memory,下一代HPC内存模型
人工智能
算家计算6 小时前
模糊高清修复真王炸!ComfyUI-SeedVR2-Kontext(画质修复+P图)本地部署教程
人工智能·开源·aigc