python定制后处理云图
用后处理软件处理的云图会出现这样或那样的不满意,其实我们可以将求解数据导出以后,借助python定制云图。
我们以fluent为例
求解完成之后,我们将我们需要做云图的物理量以ASCII导出
如下的python脚本
代码如下:
# -*- coding: utf-8 -*-
import numpy as np
import csv
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
#==============================
#该段代码来支持在图片中显示中文
#==============================
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus']=False
#保存x坐标
x=[]
#保存y坐标
y=[]
#保存导出的速度
velocity=[]
#读取csv文件,当然也可以读取类似txt之类的文件
with open(r'/home/dell/new/contour/new','r') as csvfile:
#指定分隔符为",",因为我们刚才导出时就是逗号
plots=csv.reader(csvfile,delimiter=',')
#循环读取到的文件
for row in plots:
#为了跳过文件前面的非数据行
if plots.line_num == 1:
continue
x.append(float(row[1]))
y.append(float(row[2]))
velocity.append(float(row[3]))
#如果数值过小,则视为0,防止出现非数的情况
y[y<1e-10]=0
xi=np.linspace(min(x),max(x),10000)
yi=np.linspace(min(y),max(y),10000)
#x,y坐标必须维数一致,且为二维
[X,Y]=np.meshgrid(xi,yi)
#对x,y的速度进行插值,插值的方法有'cubic','linear','nearest'
#注意传入的坐标参数需要以元组的形式成对传入
#当然matplotlib也自带griddata插值函数,该函数每个坐标是一个参数
#但matplotlib自带的griddata插值函数只能使用默认的linear插值
# Velocity=griddata((x,y),velocity,(X,Y),method='cubic')
# Velocity=griddata((x,y),velocity,(X,Y),method='nearest')
Velocity=griddata((x,y),velocity,(X,Y),method='linear')
#画出云图
#20为几条等值线,alpha为透明度,cmap对应的色彩风格
im=plt.contourf(X,Y,Velocity,20,alpha=0.75,cmap=plt.cm.jet)
#画出等值线
#color为等值线的颜色,linewidth为等值线的宽度
isoline=plt.contour(X,Y,Velocity,20,color='black',linewidth=0.1)
#在等值线上标上对应的数值
#inline表示是否将数值标在等值线上,fontsize为等值线上数值的字体的大小
plt.clabel(isoline,inline=True,fontsize=10)
#输出云图的legend
#orientation表示legend的位置,默认值为vertical,横置为horizontal
cbar=plt.colorbar(im, orientation='vertical', shrink=0.8)
#设置legend的标题
cbar.set_label('m/s')
#设置legend的范围
cbar.set_ticks(np.linspace(0,0.114,10))
#云图的标题
plt.title(u"速度云图")
#显示云图
plt.show()
最新文章
- ArcGIS Engine开发之图形查询
- 重温 w3cshool css3
- 阅读《LEARNING HARD C#学习笔记》知识点总结与摘要四
- Visual Studio Professional 2015 key
- ExtJS的MessageBox总结
- mac svn的替代品CornerStone
- ssh连接失败解决方法
- MySQL字符串函数
- [转载]监控 Linux 性能的 18 个命令行工具
- Android - 错: java.lang.IllegalStateException: Already attached
- java 多线程访问同一个对象数据保护的问题
- C# -- FTP上传下载
- Matrix [POJ3685] [二分套二分]
- 论文笔记:Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregation
- jmeter导入DB数据再优化
- 脑残式网络编程入门(六):什么是公网IP和内网IP?NAT转换又是什么鬼?
- maven五:查找jar包坐标,选择jar包版本
- GRADLE下运行main函数/执行测试用例
- SQL Server--疑难杂症之坑爹的Windows故障转移群集
- Android 仿微信的朋友圈发布(1)