python—绘图模块matplotlib

本文介绍了如何在Python中使用matplotlib模块进行数据可视化。从安装matplotlib到绘制简单折线图,再到散点图的制作,包括修改标签、线条粗细、自定义颜色以及使用颜色映射等功能,详细阐述了matplotlib的基本用法。
摘要由CSDN通过智能技术生成

1.1 安装

https://dev.windows.com/ 下载Visual Studio Community

https://pypi.python.org/pypi/matplotlib/ 下载matplotlib安装程序,查找与使用的python版本匹配的wheel文件

打开命令窗口,切换到项目文件夹使用pip安装matplotlib

 python -m pip install --user matplotlib-2.2.2-cp36-win32.whl

1.2 测试

使用python3 IDLE 尝试导入matplotlib

import matplotlib

如果没出现任何错误信息,安装成功。

2.1 绘制简单的折线图

首先导入matplotlib.pyplot,
模块pyplot中包含很多用于生成图表的函数,
将数据列表传递给函数plot(),这个函数常识根据这些数字绘制有意义的图形,
plt.show()打开matplotlib查看器

from matplotlib import pyplot as plt

squares = [1, 4, 9, 16, 25, 36]
plt.plot(squares)
plt.show()

在这里插入图片描述

2.2 修改标签文字和线条粗细

import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25, 36]
plt.plot(squares, linewidth=5, color='green')				# 设置线条粗细和颜色

plt.title('Squares Number', fontsize=14)                    # 设置标题
plt.xlabel('Number', fontsize=10, color='red')               # 设置x轴标题
plt.ylabel('Squares of Number', fontsize=10, color='blue')   # 设置y轴标题

plt.tick_params(axis='both', labelsize=10, colors='gold')    # 设置刻度尺样式

plt.show()

在这里插入图片描述
.tick_p

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值