运维联盟俱乐部

 找回密码
 立即注册
查看: 187|回复: 0

python学习笔记

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2024-1-5 00:55:47 | 显示全部楼层 |阅读模式
    1.修改python升级源

    要设置Python的升级源,可以按照以下步骤进行操作:
    首先打开命令提示符或者终端。
    输入以下命令来查看当前系统中已安装的Python版本及其路径:py -0p(Windows)或 which python3(Mac/Linux)。
    如果没有显示任何结果,则表示未安装Python。
    根据上述命令得到的信息确定需要更新的Python版本所在的目录。
    使用文本编辑器打开该目录下的"pip.ini"文件(若不存在则创建一个新文件)。
    将以下内容复制并粘贴到"pip.ini"文件中保存:
    1. [global]
    2. index-url = https://mirrors.aliyun.com/pypi/simple/
    3. trusted-host = mirrors.aliyun.com
    复制代码
    关闭文本编辑器后,重新运行pip install --upgrade pip命令来升级pip工具。
    现在就可以通过pip install <package>命令来安装、升级Python包了。

    2.安装matplotlib
    请确保你已经在本地的 Python 环境中安装了 matplotlib 库。你可以使用以下命令来安装 matplotlib:
    pip install matplotlib
    1. C:\Users\Administrator>pip install matplotlib
    2. Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
    3. Collecting matplotlib
    4.   Downloading https://mirrors.aliyun.com/pypi/packages/26/5a/27fd341e4510257789f19a4b4be8bb90d1113b8f176c3dab562b4f21466e/matplotlib-3.8.2-cp311-cp311-win_amd64.whl (7.6 MB)
    5.      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.6/7.6 MB 1.2 MB/s eta 0:00:00
    6. Collecting contourpy>=1.0.1 (from matplotlib)
    7.   Downloading https://mirrors.aliyun.com/pypi/packages/ca/2a/d197a412ec474391ee878b1218cf2fe9c6e963903755887fc5654c06636a/contourpy-1.2.0-cp311-cp311-win_amd64.whl (187 kB)
    8.      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 187.6/187.6 kB 1.1 MB/s eta 0:00:00
    9. Collecting cycler>=0.10 (from matplotlib)
    10.   Downloading https://mirrors.aliyun.com/pypi/packages/e7/05/c19819d5e3d95294a6f5947fb9b9629efb316b96de511b418c53d245aae6/cycler-0.12.1-py3-none-any.whl (8.3 kB)
    11. Collecting fonttools>=4.22.0 (from matplotlib)
    12.   Downloading https://mirrors.aliyun.com/pypi/packages/d2/54/26919780384c6dd9c3108c5ca64bbe8af45ce567e2f2493cd0cb8c596b9a/fonttools-4.47.0-cp311-cp311-win_amd64.whl (2.2 MB)
    13.      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 MB 1.2 MB/s eta 0:00:00
    14. Collecting kiwisolver>=1.3.1 (from matplotlib)
    15.   Downloading https://mirrors.aliyun.com/pypi/packages/1e/37/d3c2d4ba2719059a0f12730947bbe1ad5ee8bff89e8c35319dcb2c9ddb4c/kiwisolver-1.4.5-cp311-cp311-win_amd64.whl (56 kB)
    16.      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 56.1/56.1 kB 1.5 MB/s eta 0:00:00
    17. Requirement already satisfied: numpy<2,>=1.21 in c:\users\administrator\appdata\local\programs\python\python311\lib\site-packages (from matplotlib) (1.25.2)
    18. Collecting packaging>=20.0 (from matplotlib)
    19.   Downloading https://mirrors.aliyun.com/pypi/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl (53 kB)
    20.      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.0/53.0 kB 910.0 kB/s eta 0:00:00
    21. Collecting pillow>=8 (from matplotlib)
    22.   Downloading https://mirrors.aliyun.com/pypi/packages/43/56/f92715a873187b5eff72a4a0d2ac6258e18e9bfb0e136aafde65c49a841a/pillow-10.2.0-cp311-cp311-win_amd64.whl (2.6 MB)
    23.      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 MB 994.7 kB/s eta 0:00:00
    24. Collecting pyparsing>=2.3.1 (from matplotlib)
    25.   Downloading https://mirrors.aliyun.com/pypi/packages/39/92/8486ede85fcc088f1b3dba4ce92dd29d126fd96b0008ea213167940a2475/pyparsing-3.1.1-py3-none-any.whl (103 kB)
    26.      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.1/103.1 kB 1.2 MB/s eta 0:00:00
    27. Requirement already satisfied: python-dateutil>=2.7 in c:\users\administrator\appdata\local\programs\python\python311\lib\site-packages (from matplotlib) (2.8.2)
    28. Requirement already satisfied: six>=1.5 in c:\users\administrator\appdata\local\programs\python\python311\lib\site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)
    29. Installing collected packages: pyparsing, pillow, packaging, kiwisolver, fonttools, cycler, contourpy, matplotlib
    30. Successfully installed contourpy-1.2.0 cycler-0.12.1 fonttools-4.47.0 kiwisolver-1.4.5 matplotlib-3.8.2 packaging-23.2 pillow-10.2.0 pyparsing-3.1.1
    复制代码
    3.折线图
    以下是一个简单的示例代码,展示如何使用 matplotlib 绘制一个简单的折线图:
    1. import matplotlib.pyplot as plt

    2. # 模拟数据
    3. x = [1, 2, 3, 4, 5]
    4. y = [2, 4, 6, 8, 10]

    5. # 绘制折线图
    6. plt.plot(x, y)

    7. # 添加标签和标题
    8. plt.xlabel("X轴")
    9. plt.ylabel("Y轴")
    10. plt.title("折线图")

    11. # 显示图形
    12. plt.show()
    复制代码




    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    运维联盟俱乐部 ( 冀ICP备19036648号 )

    GMT+8, 2024-5-3 03:34 , Processed in 0.050613 second(s), 21 queries , Gzip On.

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表