使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
![](http://static.blog.csdn.net/images/category_icon.jpg)
![](http://static.blog.csdn.net/images/arrow_triangle%20_down.jpg)
![](http://static.blog.csdn.net/images/arrow_triangle%20_down.jpg)
![](http://static.blog.csdn.net/images/arrow_triangle%20_down.jpg)
版权声明:本文为博主原创文章,未经博主允许不得转载。
使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- # -*- coding: utf-8 -*-
- #**********************************************************
- import os
- import numpy as np
- import wlab #pip install wlab
- import matplotlib
- import matplotlib.cm as cm
- import matplotlib.pyplot as plt
- from matplotlib.ticker import MultipleLocator
- from scipy.interpolate import griddata
- matplotlib.rcParams['xtick.direction'] = 'out'
- matplotlib.rcParams['ytick.direction'] = 'out'
- #**********************************************************
- FreqPLUS=['F06925','F10650','F23800','F18700','F36500','F89000']
- #
- FindPath='/d3/MWRT/R20130805/'
- #**********************************************************
- fig = plt.figure(figsize=(8,6), dpi=72, facecolor="white")
- axes = plt.subplot(111)
- axes.cla()#清空坐标轴内的所有内容
- #指定图形的字体
- font = {'family' : 'serif',
- 'color' : 'darkred',
- 'weight' : 'normal',
- 'size' : 16,
- }
- #**********************************************************
- # 查找目录总文件名中保护F06925,EMS和txt字符的文件
- for fp in FreqPLUS:
- FlagStr=[fp,'EMS','txt']
- FileList=wlab.GetFileList(FindPath,FlagStr)
- #
- LST=[]#地表温度
- EMS=[]#地表发射率
- TBH=[]#水平极化亮温
- TBV=[]#垂直极化亮温
- #
- findex=0
- for fn in FileList:
- findex=findex+1
- if (os.path.isfile(fn)):
- print(str(findex)+'-->'+fn)
- #fn='/d3/MWRT/R20130805/F06925_EMS60.txt'
- data=wlab.dlmread(fn)
- EMS=EMS+list(data[:,1])#地表发射率
- LST=LST+list(data[:,2])#温度
- TBH=TBH+list(data[:,8])#水平亮温
- TBV=TBV+list(data[:,9])#垂直亮温
- #-----------------------------------------------------------
- #生成格点数据,利用griddata插值
- grid_x, grid_y = np.mgrid[275:315:1, 0.60:0.95:0.01]
- grid_z = griddata((LST,EMS), TBH, (grid_x, grid_y), method='cubic')
- #将横纵坐标都映射到(0,1)的范围内
- extent=(0,1,0,1)
- #指定colormap
- cmap = matplotlib.cm.jet
- #设定每个图的colormap和colorbar所表示范围是一样的,即归一化
- norm = matplotlib.colors.Normalize(vmin=160, vmax=300)
- #显示图形,此处没有使用contourf #>>>ctf=plt.contourf(grid_x,grid_y,grid_z)
- gci=plt.imshow(grid_z.T, extent=extent, origin='lower',cmap=cmap, norm=norm)
- #配置一下坐标刻度等
- ax=plt.gca()
- ax.set_xticks(np.linspace(0,1,9))
- ax.set_xticklabels( ('275', '280', '285', '290', '295', '300', '305', '310', '315'))
- ax.set_yticks(np.linspace(0,1,8))
- ax.set_yticklabels( ('0.60', '0.65', '0.70', '0.75', '0.80','0.85','0.90','0.95'))
- #显示colorbar
- cbar = plt.colorbar(gci)
- cbar.set_label('$T_B(K)$',fontdict=font)
- cbar.set_ticks(np.linspace(160,300,8))
- cbar.set_ticklabels( ('160', '180', '200', '220', '240', '260', '280', '300'))
- #设置label
- ax.set_ylabel('Land Surface Emissivity',fontdict=font)
- ax.set_xlabel('Land Surface Temperature(K)',fontdict=font) #陆地地表温度LST
- #设置title
- titleStr='$T_B$ for Freq = '+str(float(fp[1:-1])*0.01)+'GHz'
- plt.title(titleStr)
- figname=fp+'.png'
- plt.savefig(figname)
- plt.clf()#清除图形
- #plt.show()
- print('ALL -> Finished OK')
上面的例子中,每个保存的图,都是用同样的colormap,并且每个图的颜色映射值都是一样的,也就是说第一个图中如果200表示蓝色,那么其他图中的200也表示蓝色。
示例的图形如下:
- 顶
- 2
- 踩
- 2
使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等的更多相关文章
- 使用matplotlib的示例:调整字体-设置colormap和colorbar
使用matplotlib的示例:调整字体-设置colormap和colorbar # -*- coding: utf-8 -*- #********************************** ...
- 05. Matplotlib 1 |图表基本元素| 样式参数| 刻度 注释| 子图
1.Matplotlib简介及图表窗口 Matplotlib → 一个python版的matlab绘图接口,以2D为主,支持python.numpy.pandas基本数据结构,运营高效且有较丰富的图表 ...
- Matplotlib 图表的基本参数设置
1.图名,图例,轴标签,轴边界,轴刻度,轴刻度标签 # 图名,图例,轴标签,轴边界,轴刻度,轴刻度标签等 df = pd.DataFrame(np.random.rand(10,2),columns= ...
- (数据科学学习手札100)搞定matplotlib中的字体设置
本文示例文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 matplotlib作为数据可视化的利器,被广泛 ...
- IDEA或Webstorm设置Ctrl+滚轮调整字体大小
按Ctrl+Shift+A,出现搜索框 输入mouse: 点击打开这个设置:勾选 点击ok,之后就可以通过Ctrl+滚轮 调整字体大小了.
- 用matplotlib绘制带误差的条形图及中英文字体设置
#!/usr/bin/env python3 ## 以下是一个带误差条的条形图的例子,演示了误差条形图的绘制及中英文字体设置 import numpy as np import matplotlib ...
- IDEA设置Ctrl+滚轮调整字体大小
IDEA设置Ctrl+滚轮调整字体大小(转载) 按Ctrl+Shift+A,出现搜索框 输入mouse: 点击打开这个设置:勾选 点击ok,之后就可以通过Ctrl+滚轮 调整字体大小了.
- IDEA设置Ctrl+滚轮调整字体大小(转载)
按Ctrl+Shift+A,出现搜索框 输入mouse: 点击打开这个设置:勾选 点击ok,之后就可以通过Ctrl+滚轮 调整字体大小了. 转载自:http://www.cnblogs.com/LUA ...
- Css调整字体间距
在span div 某些元素中有时候会用到调整字体的间距,设置方法: letter-spacing:15px;
随机推荐
- centos7安装MPlyaer
最近更换了centos7系统,对新系统的操作不是太熟悉.大神轻喷.昨晚突然想要下个电影看看,结果发现系统自带的播放器支持的视频格式有限,google查了一下,他们推荐使用MPlayer.于是经过一通g ...
- Linux 解压压缩命令
一.概述: 1.压缩命令: 命令格式:tar -zcvf 压缩文件名.tar.gz 被压缩文件名 可先切换到当前目录下.压缩文件名和被压缩文件名都可加入路径. 2.解压缩命令: 命令格式:t ...
- 2017-03-05 CentOS中结合Nginx部署dotnet core Web应用程序
Visual Studio Live 倒计时2天,当然这是美国倒计时两天,中国应该是在3月8日的凌晨,正值"3.8妇女节".提前祝广大的女性同志节日快乐,当然还有奋斗在一线的程序媛 ...
- jsp用tags传递参数
<computer:trangleTag sideA="12" sideB="12" sideC="12"/>表示以字符串传递s ...
- 分布式_理论_08_Consistent Hash(一致性哈希算法)
一.前言 五.参考资料 1.分布式理论(八)—— Consistent Hash(一致性哈希算法)
- LeetCode OJ:Delete Node in a Linked List(链表节点删除)
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- Nhibernate系列学习之(三) Criteria查询表达式增删改查
Criteria查询表达式: 正如我们所见,Expression对查询语句的表达式进行了封装和限制,下表列出了Expression所有的方法,以及每个方法所对应的查询表达式及其限制. Restrict ...
- java 网页 保存上传文件
网页请求提交到另外一个jsp 进行处理 index.jsp <%@ page language="java" import="java.util.*" p ...
- 浅谈FFT(快速傅里叶变换)
本文主要简单写写自己在算法竞赛中学习FFT的经历以及一些自己的理解和想法. FFT的介绍以及入门就不赘述了,网上有许多相关的资料,入门的话推荐这篇博客:FFT(最详细最通俗的入门手册),里面介绍得很详 ...
- c# Http请求之HttpClient
利用HttpClient进行Http请求,基于此,简单地封装了下: using System; using System.Collections.Generic; using System.Colle ...