数据可视化-Matplotlib绘制简单折线图

这篇博客介绍了如何使用Python的Matplotlib库进行数据可视化,包括绘制折线图、散点图,调整标签、线条粗细,自定义颜色,使用颜色映射以及自动保存图像。通过实例展示了如何修改图表细节,如删除数据点轮廓,以及如何根据数据自动计算图形。同时,提供了颜色映射的参考资源和自动保存图像的方法。

要查看使用matplotlib可制作的各种图表,请访问 http://matplotlib.org/ 的示例画廊。单击画廊中的图表,就可查看用于生成图表的代码。

import matplotlib.pyplot as plt

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

解析:

  • 首先要导入pyplot模块,这里还给它指定了别名plt,以简化代码
  • 创建一个平方数列squares = [1, 4, 9, 16, 25]
  • 将数列传给函数plot(),这个函数尝试根据这些数字绘制出有意义的图形
  • plt.show()打开matplotlib查看器,并显示绘制的图形

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

import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]

## 1. 线条粗细
plt.plot(squares, linewidth=5)  # linewidth参数用来设置线条粗细

plt.show()

import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]

## 1. 线条粗细
plt.plot(squares, linewidth=5)  # linewidth参数用来设置线条粗细

## 2.设置标题
plt.title('title', fontsize=24)  # fontsize参数用来指定文字大小

plt.show()

import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]

## 1. 线条粗细
plt.plot(squares, linewidth=5)  # linewidth参数用来设置线条粗细

## 2.设置标题
plt.title('title', fontsize=24)  # fontsize参数用来指定文字大小

## 3.为坐标轴添加标签
plt.xlabel('xvalue', fontsize=24)
plt.ylabel('yvalue', fontsize=24)

plt.show()

import matplotlib.pyplot as plt

squares = [1, 4, 9, 16, 25]

## 1. 线条粗细
plt.plot(squares, linewidth=5)  # linewidth参数用来设置线条粗细

## 2.设置标题
plt.title('title', fontsize
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值