python数据分析课程笔记 | 第四章 Matplotlib数据可视化(下)

数据可视化各个图表 饼图,折线图,环形图,阶梯图,茎叶图.... 阅读详情

4.5 完善统计图形

(1)图例和画布使用

在这里插入图片描述
图例中legend中loc中的位置和数字关系的使用:

  • best:0
  • upper right:1
  • upper left:2
  • lower left:3
  • lower right:4
  • right:5
  • center left:6
  • center right:7
    在这里插入图片描述

(2)图形添加内容

在这里插入图片描述

4.6 图像样式高级操作

(1)绘制双坐标轴

import pandas as pd
import matplotlib.pyplot as plt
import os

os.chdir(r'C:\Users\Administrator.DESKTOP-0L8IC5U\Desktop\数据分析\data')

data = pd.read_csv('supermarket_sales.csv')
data_1 = data.groupby('Date').mean()
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(data_1.index, data_1.cogs, color='blue', label='cogs')
plt.legend(loc='upper left')
ax1.set_ylabel('情况1')
ax2 = ax1.twinx()
ax2.plot(data_1.index, data_1.Rating, color='red', label='Rating')
ax2.set_ylabel('情况2')
plt.legend(loc='upper center')
plt.show()

在这里插入图片描述

(2)多个图形合并

import pandas as pd
import matplotlib.pyplot as plt
import os

os.chdir(r'C:\Users\Administrator.DESKTOP-0L8IC5U\Desktop\数据分析\data')

GDP_data = pd.read_csv('gdp_csv.csv')[:40]

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

plt.figure(figsize=(16, 9))
plt.subplot(121)
plt.plot(GDP_data['Year'], GDP_data['Value'], c='c')
plt.xlabel('年份', fontsize=12)
plt.ylabel('GDP', fontsize=18)
plt.xticks(rotation=45)
plt.subplot(122)
plt.bar(x=GDP_data.Year, height=GDP_data.Value, color='r')
plt.show()

在这里插入图片描述
在这里插入图片描述

4.7 高级绘图

(1)Seaborn基础

在这里插入图片描述

import pandas as pd
import matplotlib.pyplot as plt
import os
import seaborn as sns

os.chdir(r'C:\Users\Administrator.DESKTOP-0L8IC5U\Desktop\数据分析\data')
GDP = pd.read_csv('gdp_csv.csv')[:49]

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# 第一种调用方式
plt.style.use('seaborn')
plt.bar(x=GDP.Year, height=GDP.Value, tick_label=GDP.Year, color='steelblue')
plt.xticks(rotation=45)
plt.ylabel('GDP')
plt.show()

# 第二种调用方式
sns.set(style='darkgrid', context='notebook', font_scale=1.2)
python数据分析课程笔记 | 第四章 Matplotlib数据可视化(上) 目录:4.1 matplotlib绘图基础4.2 简单图形绘制(1)饼图(2)条形图(3)直方图(4)散点图4.3 图形基本设置4.4 统计图形实战(1)柱状图(2)直方图(3)箱线图(4)散点图(5)折线图 4.1 matplotlib绘图基础 import numpy as np import matplotlib.pyplot as plt # 解决中文乱码问题 plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.uni 阅读详情

相关推荐

【大学生课程】《Python数据分析》课程大作业要求

《Python数据分析》课程大作业要求 大作业要求 评分标准 一、评分规范基本要求 1、按时上交纸质文档和电子文档… 10分 2、数据分析方法及分析步骤…20分 3、代码…50分 3.1 算法描述正确(10分) 3.2 算法分析(20分) 3.3 代码截图(20分) 4、个人总结…20分 4.1 对数据分析的理解(10分) 4.2 学习数据分析课程的体会(10分) 考核目标 1、掌握Pandas的读写操作 2、正确使用预处理技术过滤数据 3、熟悉Matplotlib库绘制各种图表 4、会基于数据进行独立分析

俺的博客 1万+

数据分析基础:数据可视化+数据分析报告(Python实现)

提示:数据展现用来直观高效地向他人展示数据分析结果,也称数据可视化。本文介绍通过python如何快速调用第三方库实现数据可视化。本文内容为日常学习记录,提供了最基础的Python数据可视化实现方式,有兴趣可通过Python自主实现,并逐渐深入。 一、数据可视化实现方式 Python 作为一种编程语言,通过调用第三方可视化库作图,覆盖的图表种类很多,定制化非常强,并且免费。再加上 Python 基本涵盖了数据分析的整个流程:从数据处理到数据分析,再到数据展现。可以说是行云流水,一气呵成。所以我们选择使用P.

The丶Star 1万+

Python数据分析实战—用matplotlib实现数据可视化(1)

《Python数据分析实战》 matplotlib优点: 使用起来极其简单 以渐进、交互式方式实现数据可视化 表达式和文本使用LaTeX排版 对图像元素控制力更强 可输出PNG、PDF、SVG和EPS等多种格式 1.matplotlib架构 matplotlib的主要任务之一,就是提供一套表示和操作图形对象(主要对象)以及它的内部对象的函数和工具。 然而,matplotlib...

yangyang的专栏 5352

python数据可视化与matplotlib

1、python的数据分析到底是啥?python数据可视化怎么做? (1)python是一个强大的编程语言。数据分析是一个一目了然,就是将数据进行分析,看看能得出什么结论。那python的数据分析到底是啥?其实就是通过这个语言将数据分析做出来,更加便捷化,更加速度化。 2、数据可视化概述 数据可视化是在整个数据分析非常重要的一个辅助工具,可以清晰的理解数据,从而调整我们的分析方法。 能将数据进行可视化,更直观的呈现 使数据更加客观、更具说服力 如图所示: 2、python中的数据可视化(Matplotli

zff20010503的博客 1626

Python数据可视化—matplotlib笔记

在参加数据挖掘竞赛中,经常需要对数据进行可视化。今天有空就对数据可视化—matplotlib这块内容系统的整理下,方便查找使用。本文来自于对《利用python进行数据分析》以及网上一些博客的总结。 1 matplotlib简介 matplotlib是Pythom可视化程序库的泰斗,经过几十年它仍然是Python使用者最常用的画图库。有许多别的程序库都是建立在它的基础上或直接调用它,

奔跑的小乌龟 6386

【数据可视化】Matplotlib 入门到精通学习笔记(超详细)

如果将文本数据与图表数据相比较,人类的思维模式更适合于理解后者,原因在于图表数据更加直观且形象化,它对于人类视觉的冲击更强,这种使用图表来表示数据的方法被叫做数据可视化。 当使用图表来表示数据时,我们可以更有效地分析数据,并根据分析做出相应的决策。在学习 Matplotlib 之前,了解什么是数据可视化!图表为更好地探索、分析数据提供了一种直观的方法,它对最终分析结果的展示具有重要的作用。当您对一个数据集进行分析时,如果使用数据可视化的方式,那么您会很容易地确定数据集的分类模式、缺失数据、离群值等等。下图展

2201_75381449的博客 1636

python数据分析课程总结

数据分析是利用数学、统计学理论与实践相结合的科学统计分析方法,对Excel数据、数据库中的数据、收集的大量数据、网页抓取的数据进行分析,从中提取有价值的信息并形成结论进行展示的过程。数据分析实际就是通过总结数据的规律来解决业务问题,以帮助在实际工作中管理者做出判断和决策。数据分析包括如下几个主要内容1.现状分析:分析已经发生了什么2.原因分析:分析为什么会出现这种现状3.预测分析:预测未来可能发生什么。

moguangde的博客 1571

如何使用python的 Pyecharts库 制作 GDP 动态柱状图?

如何使用python的 Pyecharts库 制作 GDP 动态柱状图?

weixin_43263566的博客 1275

Python数据分析之Matplotlib数据可视化实例

Matplotlib数据可视化的应用实例 分析 :2000至2017年各季度国民生产总值数据 分析国民生产总值: # -- coding:utf-8 -- import numpy as np import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = 'SimHei' # 设置中文显示,否则可能无法显示中文或者是各种...

CJW的博客 1万+

MIMIC-IV数据库中患者院内死亡的单因素生存分析

目的 由易到难,对mimic-iv的查询进行实际操作,体现先前文章中提到的mimic-iv数据查询的规律。 数据分析计划 死亡,是重症患者最重要的结局指标,在MIMIC数据库中收录了院内死亡的数据,以及进出ICU的时间(和进出医院的时间),所以我们可以获得是否死亡,以及从入ICU(或入院)到死亡发生之间的时间,有了这两个指标,我们可以通过Cox单因素(参数和非参数)模型来观察ICU(和医院)内死亡的趋势,以及某个变量(比如,性别和种族等)对死亡趋势的影响,以为后续的分析奠定基础。 数据的获取 我们需要数个变

skyskytotop的博客 3185

5分钟搞懂深度学习如何革新声源定位:从GCC-PHAT到DNN的实战对比

本文深入对比了深度学习与传统GCC-PHAT方法在声源定位领域的实战表现。通过具体实验数据,展示了DNN模型在强混响、低信噪比等复杂场景下,如何实现定位准确率的显著提升,并探讨了其数据驱动范式带来的鲁棒性优势与工程部署挑战。

3a9bq4r8t2y的博客 223

opencode完整使用指南:从安装配置到Agent式编程实战

AI编程工具正从辅助补全向智能体协作演进。编程智能体不仅理解项目全局,还能自主执行原子级重构、测试验证等工程任务,显著提升研发效能。以opencode为代表的开源终端AI编程工具,凭本地优先和灵活模型接入成为技术团队新宠。本文围绕opencode的完整使用链路展开,从Node.js环境准备、npm全局安装,到解决Windows环境变量配置问题,再到接入OpenAI、Anthropic或多模型管理平台,梳理一套标准化接入方案。同时演示VSCode插件调用、LSP语义分析及Playwright驱动的浏览器自动化

weixin_28837817的博客 319

手把手教你用LTspice仿真TVS二极管:从选型验证到波形分析全流程

本文详细介绍了如何使用LTspice仿真TVS二极管,从选型验证到波形分析的全流程。通过搭建仿真环境、核心参数验证和系统级防护策略,帮助工程师低成本评估TVS性能,优化电路设计。特别适用于电源设计和接口防护领域,提升工作效率和设计准确性。

weixin_29234239的博客 646

【微信读书】数据内容接口逆向解析实战:从请求捕获到文本提取

本文详细解析了微信读书网页版数据内容接口的逆向工程实战过程。通过浏览器开发者工具捕获网络请求,定位关键API接口,并深入JavaScript代码分析数据解析逻辑,最终实现从请求模拟到文本提取的完整流程。文章旨在技术学习,探讨Web应用数据交互原理,帮助开发者理解现代前端数据流与编码机制。

game4的博客 420

用LTspice仿真CMOS反相器功耗?这份避坑指南能省你3天调试时间

本文详细介绍了如何使用LTspice准确仿真CMOS反相器的功耗,包括动态功耗、短路功耗和静态功耗的测量技巧。通过工程实践指南,帮助电子工程师避开常见陷阱,优化仿真参数设置,提升仿真结果的可靠性,节省调试时间。

w7x8y9z的博客 189

stm32最小系统_完成一个最小FOC矢量控制系统所需的基本模块和功能配置

当我们读懂 FOC 矢量控制的基本原理之后,便迫不及待的想动手尝试,去实现一个矢量控制系统,让电机先转起来,有一个直观的感受。因此,我们需要设计实现一个矢量控制的最小系统,具备矢量控制的基本功能,满足电机矢量运行的基本条件。首先,看一下矢量控制的基本架构:矢量控制架构如上图所描述,矢量控制系统包括实时电流的采集、clarke 变换、park 变换、SVPWM 、实时角度的反馈和计算以及电流环和速...

weixin_39524048的博客 1784

Qt之QMqtt 发送图片数据

MQTT是一个基于客户端-服务器的消息发布/订阅传输协议;MQTT协议是轻量、简单、开放和易于实现的,这些特点使它适用范围非常广泛;在很多情况下,包括受限的环境中,如:机器与机器(M2M)通信和物联网(IoT);其在,通过卫星链路通信传感器、偶尔拨号的医疗设备、智能家居、及一些小型化设备中已广泛使用;

Ilson_的博客 1437

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: python数据分析课程笔记 | 第四章 Matplotlib数据可视化(上)
下一篇: python数据分析课程笔记 | 第五章 Python统计分析(上)
啥都不会的怪蜀黍
博客等级 码龄7年 2粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值