数据可视化matplotlib

代码及注释

# -*- coding: utf-8 -*-


import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
from scipy import stats


# 创建figure
fig = plt.figure()

ax1 = fig.add_subplot(2,3,1)
ax2 = fig.add_subplot(2,3,2)
ax3 = fig.add_subplot(2,3,3)
ax4 = fig.add_subplot(2,3,4)

random_arr = np.random.randn(100)
plt.plot(random_arr)

#
x = np.linspace(-5, 15, 50)
ax2.plot(x, sp.stats.norm.pdf(x=x, loc=5, scale=2))
ax2.hist(sp.stats.norm.rvs(loc=5, scale=2, size=200), bins=50, normed=True, color='red', alpha=0.5)

# 绘制直方图
ax1.hist(np.random.randn(100), bins=10, color='b', alpha=0.3)

# 绘制散点图
x = np.arange(50)
y = x + 5 * np.random.rand(50)
ax3.scatter(x, y)

# 柱状图
ax5 = fig.add_subplot(2,3,5)
x = np.arange(5)
y1, y2 = np.random.randint(1, 25, size=(2, 5))
width = 0.25
ax5.bar(x, y1, width, color='r')
ax5.bar(x+width, y2, width, color='g')
ax5.set_xticks(x+width)
ax5.set_xticklabels(['a', 'b', 'c', 'd', 'e'])
plt.show()

# 矩阵绘图
m = np.random.rand(10,10)
plt.imshow(m, interpolation='nearest', cmap=plt.cm.ocean)
plt.colorbar()
plt.show()

# plt.subplots()
fig, subplot_arr = plt.subplots(2,2)
subplot_arr[0,0].hist(np.random.randn(100), bins=10, color='b', alpha=0.3)
plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据可视化的原理是使用matplotlib这个Python库来创建图表和可视化效果。matplotlib库中最常用的模块是pyplot,它提供了一系列函数来创建、定制和展示图表。[1] 在使用matplotlib进行数据可视化时,首先需要导入matplotlib.pyplot模块。然后,可以使用plot函数来创建图表,传入x和y的数据作为参数。接下来,使用show函数来显示图表Matplotlib是数据分析三剑客中的一员,它可以与NumPy和Pandas一起使用,帮助我们更好地理解和分析数据。通过绘制饼图、柱状图、条形图等不同类型的图表,可以直观地展示数据分析的结果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Python之数据可视化——matplotlib系统介绍(一)](https://blog.csdn.net/OuKman/article/details/108815083)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Matplotlib 数据分析可视化](https://download.csdn.net/download/weixin_26876073/19667161)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值