Python-Matplotlib(2)打造一个完整的折线图
来源:互联网 发布:软件企业评估证书 编辑:程序博客网 时间:2024/04/28 09:37
import pandas as pdimport matplotlib.pyplot as pltunrate = pd.read_csv('unrate.csv')unrate['DATE'] = pd.to_datetime(unrate['DATE'])first_twelve = unrate[0:12]plt.plot(first_twelve['DATE'], first_twelve['VALUE'])plt.xticks(rotation=90)plt.xlabel('Month')plt.ylabel('Unemployment Rate')plt.title('Monthly Unemployment Trends, 1948')plt.show()
#add_subplot(first,second,index) first means number of Row,second means number of Column.import matplotlib.pyplot as pltfig = plt.figure()ax1 = fig.add_subplot(3,2,1)ax2 = fig.add_subplot(3,2,2)ax2 = fig.add_subplot(3,2,6)plt.show()
import numpy as npfig = plt.figure()#fig = plt.figure(figsize=(3, 3))ax1 = fig.add_subplot(2,1,1)ax2 = fig.add_subplot(2,1,2)ax1.plot(np.random.randint(1,5,5), np.arange(5))ax2.plot(np.arange(10)*3, np.arange(10))plt.show()
unrate['MONTH'] = unrate['DATE'].dt.monthunrate['MONTH'] = unrate['DATE'].dt.monthfig = plt.figure(figsize=(6,3))plt.plot(unrate[0:12]['MONTH'], unrate[0:12]['VALUE'], c='red')plt.plot(unrate[12:24]['MONTH'], unrate[12:24]['VALUE'], c='blue')plt.show()
fig = plt.figure(figsize=(10,6))colors = ['red', 'blue', 'green', 'orange', 'black']for i in range(5): start_index = i*12 end_index = (i+1)*12 subset = unrate[start_index:end_index] plt.plot(subset['MONTH'], subset['VALUE'], c=colors[i])plt.show()
fig = plt.figure(figsize=(10,6))colors = ['red', 'blue', 'green', 'orange', 'black']for i in range(5): start_index = i*12 end_index = (i+1)*12 subset = unrate[start_index:end_index] label = str(1948 + i) plt.plot(subset['MONTH'], subset['VALUE'], c=colors[i], label=label)plt.legend(loc='best')#print help(plt.legend)plt.show()
fig = plt.figure(figsize=(10,6))colors = ['red', 'blue', 'green', 'orange', 'black']for i in range(5): start_index = i*12 end_index = (i+1)*12 subset = unrate[start_index:end_index] label = str(1948 + i) plt.plot(subset['MONTH'], subset['VALUE'], c=colors[i], label=label)plt.legend(loc='upper left')plt.xlabel('Month, Integer')plt.ylabel('Unemployment Rate, Percent')plt.title('Monthly Unemployment Trends, 1948-1952')plt.show()
阅读全文
0 0
- Python-Matplotlib(2)打造一个完整的折线图
- python用matplotlib画折线图
- Python-Matplotlib(1)画折线图
- python使用matplotlib绘制折线图教程
- 【Python-3.5】matplotlib做简单折线图
- 【Python-3.5】matplotlib绘制气温折线图
- 使用matplotlib绘制简单的折线图
- 用~/.vimrc打造一个完整python环境
- Matplotlib画折线图
- Matplotlib画出折线图
- Matplotlib折线图
- matplotlib-折线图
- Matplotlib绘制折线图
- python实战二:使用CSV数据绘制带数据标志的折线图(matplotlib)
- python 数据可视化 matplotlib学习一:绘制简单的折线图
- Python学习之matplotlib 绘制折线图详解
- 【Python】Matplotlib画图(四)——折线图
- python matplotlib从文件中读取数据绘制折线图
- Django的MVC架构(1)
- forward和redirect的本质区别
- Arya and Bran & Game of the Rows & Multiple Clocks
- 1.1最大子列和问题
- 兰灯链接
- Python-Matplotlib(2)打造一个完整的折线图
- 《网易编程题》疯狂队列
- java集合之TreeMap
- hdu-1575-Tr A(矩阵快速幂入门题)
- 博弈论
- 在 Vim 中优雅地查找和替换
- learn c第一章:简介(关键词和标识符)
- 商业公司应该如何配备数据分析团队?
- Codeforces Round #428 (Div. 2)(A+B)