matplotlib

少有人知的python数据科学库

非 Y 不嫁゛ 提交于 2021-02-02 04:05:46
Python是门很神奇的语言,历经时间和实践检验,受到开发者和数据科学家一致好评,目前已经是全世界发展最好的编程语言之一。简单易用,完整而庞大的第三方库生态圈,使得Python成为编程小白和高级工程师的首选。 在本文中,我们会分享不同于市面上的python数据科学库(如numpy、padnas、scikit-learn、matplotlib等),尽管这些库很棒,但是其他还有一些不为人知,但同样优秀的库需要我们去探索去学习。 1. Wget 从网络上获取数据被认为是数据科学家的必备基本技能,而Wget是一套非交互的基于命令行的文件下载库。ta支持HTTP、HTTPS和FTP协议,也支持使用IP代理。因为ta是非交互的,即使用户未登录,ta也可以在后台运行。所以下次如果你想从网络上下载一个页面,Wget可以帮到你哦。 安装 pip isntall wget 用例 import wget url = 'http://www.futurecrew.com/skaven/song_files/mp3/razorback.mp3' filename = wget.download(url) Run and output 100% [................................................] 3841532 / 3841532 filename

李宏毅 线性回归预测PM2.5

强颜欢笑 提交于 2021-02-02 02:06:40
作业说明   给定训练集train.csv,要求根据前9个小时的空气监测情况预测第10个小时的PM2.5含量。 训练集介绍:   (1):CSV文件,包含台湾丰原地区240天的气象观测资料(取每个月前20天的数据做训练集,12月X20天=240天,每月后10天数据用于测试,对学生不可见);   (2):每天的监测时间点为0时,1时......到23时,共24个时间节点;   (3):每天的检测指标包括CO、NO、PM2.5、PM10等气体浓度,是否降雨、刮风等气象信息,共计18项; (4):数据集 https://github.com/datawhalechina/leeml-notes/blob/master/docs/Homework/HW_1/Dataset 数据处理 【下文中提到的“数据帧”并非指pandas库中的数据结构DataFrame,而是指一个二维的数据包】 根据作业要求可知,需要用到连续9个时间点的气象观测数据,来预测第10个时间点的PM2.5含量。针对每一天来说,其包含的信息维度为(18,24)(18项指标,24个时间节点)。可以将0到8时的数据截 取出来,形成一个维度为(18,9)的数据帧,作为训练数据,将9时的PM2.5含量取出来,作为该训练数据对应的label;同理可取1到9时的数据作为训练用的数据帧,10时的PM2.5含量作为label......以此

Pandas Plotting Display all date values on x-axis (matplolib only displays few values) formatted as MMM-YYYY [duplicate]

落花浮王杯 提交于 2021-01-31 05:48:46
问题 This question already has an answer here : MonthLocator in Matplotlib (1 answer) Closed last month . import os import pandas as pd import matplotlib.pyplot as plt import datetime df = pd.read_excel(DATA_DIR+"/"+file_list[0], index_col="Date") df.head(5) smooth = df['Pur. Rate'].rolling(window=20).mean() smooth.plot() I get the following graph and need to plot all the date values for every MONTH-YEAR on the x-axis. I want to display all the months and years formatted diagonally on the x-axis

Pandas Plotting Display all date values on x-axis (matplolib only displays few values) formatted as MMM-YYYY [duplicate]

隐身守侯 提交于 2021-01-31 05:45:08
问题 This question already has an answer here : MonthLocator in Matplotlib (1 answer) Closed last month . import os import pandas as pd import matplotlib.pyplot as plt import datetime df = pd.read_excel(DATA_DIR+"/"+file_list[0], index_col="Date") df.head(5) smooth = df['Pur. Rate'].rolling(window=20).mean() smooth.plot() I get the following graph and need to plot all the date values for every MONTH-YEAR on the x-axis. I want to display all the months and years formatted diagonally on the x-axis

matplotlib修改坐标轴刻度值,刻度个数

半城伤御伤魂 提交于 2021-01-30 12:39:06
Matplotlib 中的 ticker 模块用于支持坐标轴刻度的修改,调用下列命令可以初步查看主副坐标轴刻度的数值定位方式(locator)与具体格式(formatter)等。 详情: http://matplotlib.org/api/axis_api.html ax .xaxis .get_major_ticks ( ) ax .xaxis .get_minor_ticks ( ) ax .xaxis .get_major_locator ( ) ax .xaxis .get_minor_locator ( ) ax .xaxis .get_major_formatter ( ) ax .xaxis .get_minor_formatter ( ) 设置主副刻度对象属性 # encoding:utf-8 import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator, FormatStrFormatter import numpy as np def test(): ax = plt.subplot( 111) # 注意:一般都在ax中设置,不再plot中设置 t = np.arange( 0.0, 100.0, 1) s = np.sin( 0.1 * np.pi * t) * np

matplotlib| 01. 坐标轴刻度样式设置

冷暖自知 提交于 2021-01-30 11:52:31
01. 坐标轴刻度样式设置 import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import AutoMinorLocator,MultipleLocator,FuncFormatter 主要使用到的函数 MultipleLocator() 定义主刻度线的间隔 AutoMinorLocator() 定义次刻度的间隔 FuncFormatter() 设置自定义的刻度标签格式(如小数位数) FormatStrFormatter() 设置自定义的刻度标签格式(如小数位数、添加单位符号) ax.xaxis.set_major_locator() ax.xaxis.set_minor_locator() 设置主/次坐标轴的刻度位置 ax.xaxis.set_major_formatter ax.xaxis.set_minor_formatter() 设置主/次坐标轴的刻度 格式 (小数位数) ax.tick_params() 设置主/次坐标轴刻度线和刻度标签 样式 (大小、颜色) ax.xaxis.get_ticklabels() ax.xaxis.get_ticklines() 获取主/次坐标轴刻度线和刻度标签对象 x=np.linspace(0.5,3.5,100) y=np.sin(x)

Python matplotlib custom colorbar for plotted lines with manually assigned colors

你说的曾经没有我的故事 提交于 2021-01-29 21:43:11
问题 I'm trying to define a colorbar for the following type of plot. import matplotlib.pyplot as plt import numpy as np for i in np.arange(0,10,0.1): plt.plot(range(10),np.ones(10)*i,c=[i/10.,0.5,0.25]) plt.show() This is just a simplified version of my actual data, but basically, I'd like a series of lines plotted and colored by another variable with a colorbar key. This is easy to do in scatter, but I can't get scatter to plot connected lines. Points are too clunky. I know this sounds like basic

3d vectors in python [duplicate]

十年热恋 提交于 2021-01-29 20:59:01
问题 This question already has answers here : Plotting a 3d cube, a sphere and a vector in Matplotlib (3 answers) Putting arrowheads on vectors in matplotlib's 3d plot (2 answers) Closed 6 years ago . The code below allows me to plot vectors at different vertical levels but these vectors do not have arrow heads attached to them. I was wondering how should I modify this code so that I can get arrowheads at the end of the vectors? #!/usr/bin/python import matplotlib.pyplot as plt from mpl_toolkits

Matplotlib: GRID and COLORMAP with TRISURF

流过昼夜 提交于 2021-01-29 20:50:50
问题 I want to put a grid on my surface but it doesn't work even with linewidth different from zero, also I would like to plot a colormap that changes the color with Z axis, so the walls should appear with the same color cos they are points at 0.5 in Z. Hope somebody can help me, thanks. This is the part of my code I'm having problem with: fig = plt.figure() ax = Axes3D(fig) surf = ax.plot_trisurf(x, y, z, cmap=plt.cm.get_cmap('jet',4), shade=False,linewidth=0.1, antialiased=False ) This is my

matplotlib in second window pyqt5

心已入冬 提交于 2021-01-29 20:12:38
问题 I wish to plot a matplotlib graph in a second window when a button is clicked in the main window. Using https://matplotlib.org/examples/user_interfaces/embedding_in_qt4.html , which plots a graph in the main window, I wrote the code below. The matplotlib graph is indeed plotted in a second window, but it has a very small size and I don't understand how to adjust the size of the graph to the window. May I have some help? from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication,