Python数据分析入门篇(一)利用matpiotlib库进行图像的简单绘制

一.绘制简单的线图

import matplotlib.pyplot as plt
a = [1, 2, 3, 4, 5, 6]
b = [1, 2, 3, 4, 5, 6]
plt.plot(a, b, color = 'yellow', marker = 'o', linestyle = 'solid')
plt.title("title")
plt.xlabel("x")
plt.ylabel("y")
plt.grid()#绘制方格
plt.show()

绘制效果:

二. 绘制条形图

import matplotlib.pyplot as plt
a = [1, 2, 3, 4, 5, 6]
b = [1, 2, 3, 4, 5, 6]
a_label = ['1', '2', '3', '4', '5', '6']
plt.xticks(a, a_label)#绘制x轴标签
plt.bar(a, b, width= 0.5, bottom= 1, color = 'green')
plt.show()
#width:单个直方图的宽度, bottom:y轴的起点

绘制效果

 三. 绘制复杂线图

import matplotlib.pyplot as plt
import numpy as np
a = [1, 2, 4, 6, 8, 10, 12, 24]
b = [1, 2, 4, 8, 16, 32, 64, 128]
c = [128, 64, 32, 16, 8, 4, 2, 1]
d = np.random.randint(1, 100, 8)#随机生成8个
x = [i for i in range(0, 8)]
plt.plot(x, a, linestyle = '-', label = 'a')#实线
plt.plot(x, b, linestyle = '-.', label = 'b')#点虚线
plt.plot(x, c, linestyle = ':', label = 'c')#点线
plt.plot(x, d, linestyle = '--', label = 'd')#虚线
plt.legend()#设置图例
plt.title('title')
plt.show()

绘制效果

四. 绘制散点图

import matplotlib.pyplot as plt
a = [1, 2, 4, 6, 8, 10, 12, 24]
b = [1, 2, 4, 8, 16, 32, 64, 128]
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
plt.scatter(a, b)
for a, b, labels in zip(a, b, labels):
    plt.annotate(labels, xy = (a, b), xytext = (-5, 5), textcoords = 'offset points', color = 'm')
# plt.annotate用于标注文字
# plt.annotate(s='str', #s为标注的文本内容
# 	xy=(x,y) ,          #xy为被标注的坐标点
# 	xytext=(l1,l2) ,    #xytext为被标注文字的坐标位置
# 	...
# )
plt.title('title')
plt.show()

绘制效果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值