Python教程

Python科研绘图20211129:伪彩色图

本文主要是介绍Python科研绘图20211129:伪彩色图,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

 

 

import pandas as pd
import datetime
import h5py
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.colors import Normalize

from sys import exit
import argparse
import os

# coding=utf-8

#energy线图
k = np.loadtxt(open("k1.csv","rb"),delimiter=",",skiprows=0)
w = np.loadtxt(open("w1.csv","rb"),delimiter=",",skiprows=0)
wk = np.loadtxt(open("wk1.csv","rb"),delimiter=",",skiprows=0)
print("k="+str(k.shape))
print("w="+str(w.shape))
print("wk="+str(wk.shape))
X, Y = np.meshgrid(k, w)



k = np.loadtxt(open("k1.csv","rb"),delimiter=",",skiprows=0)
w = np.loadtxt(open("w1.csv","rb"),delimiter=",",skiprows=0)
wk = np.loadtxt(open("wk1.csv","rb"),delimiter=",",skiprows=0)
print("k="+str(k.shape))
print("w="+str(w.shape))
print("wk="+str(wk.shape))
X, Y = np.meshgrid(k, w)

# plot forward plopagating waves
fig = plt.figure()
ax1 = fig.add_subplot(111)
contourdata = ax1.pcolormesh(X, Y, wk, cmap='plasma',norm=Normalize(vmin=-10, vmax=-1))
pp = fig.colorbar(contourdata, ax=ax1, orientation='vertical')
plt.xlabel('$k$')
plt.ylabel('$w$')
pp.set_label('$\log E_x$')
plt.savefig("Ex(k,w).png")
plt.close()



# plot forward plopagating waves
wk2 = np.loadtxt(open("wk2.csv","rb"),delimiter=",",skiprows=0)
fig = plt.figure()
ax1 = fig.add_subplot(111)
contourdata = ax1.pcolormesh(X, Y, wk2, cmap='plasma',norm=Normalize(vmin=-10, vmax=-1))
pp = fig.colorbar(contourdata, ax=ax1, orientation='vertical')
plt.xlabel('$k$')
plt.ylabel('$w$')
pp.set_label('$\log E_y$')
plt.savefig("Ey(k,w).png")
plt.close()

# plot forward plopagating waves
wk3 = np.loadtxt(open("wk3.csv","rb"),delimiter=",",skiprows=0)
fig = plt.figure()
ax1 = fig.add_subplot(111)
contourdata = ax1.pcolormesh(X, Y, wk3, cmap='plasma',norm=Normalize(vmin=-10, vmax=-1))
pp = fig.colorbar(contourdata, ax=ax1, orientation='vertical')
plt.xlabel('$k$')
plt.ylabel('$w$')
pp.set_label('$\log E_z$')
plt.savefig("Ez(k,w).png")
plt.close()

# plot forward plopagating waves
wk4 = np.loadtxt(open("wk4.csv","rb"),delimiter=",",skiprows=0)
fig = plt.figure()
ax1 = fig.add_subplot(111)
contourdata = ax1.pcolormesh(X, Y, wk4, cmap='plasma')
pp = fig.colorbar(contourdata, ax=ax1, orientation='vertical')
plt.xlabel('$k$')
plt.ylabel('$w$')
pp.set_label('$\log B_y$')
plt.savefig("By(k,w).png")
plt.close()

# plot forward plopagating waves
wk5 = np.loadtxt(open("wk5.csv","rb"),delimiter=",",skiprows=0)
fig = plt.figure()
ax1 = fig.add_subplot(111)
contourdata = ax1.pcolormesh(X, Y, wk5, cmap='plasma',norm=Normalize(vmin=-10, vmax=-1))
pp = fig.colorbar(contourdata, ax=ax1, orientation='vertical')
plt.xlabel('$k$')
plt.ylabel('$w$')
pp.set_label('$\log B_z$')
plt.savefig("Bz(k,w).png")
plt.close()

# plot forward plopagating waves
b0=0.1
by=(10**wk4)
bz=(10**wk5)
bw = (by ** 2 + bz ** 2) / b0 ** 2

fig = plt.figure()
ax1 = fig.add_subplot(111)
contourdata = ax1.pcolormesh(X, Y,np.log10(bw), cmap='plasma')
pp = fig.colorbar(contourdata, ax=ax1, orientation='vertical')
plt.xlabel('$k$')
plt.ylabel('$w$')
pp.set_label('$\log B_w$')
plt.savefig("Bw(k,w).png")
plt.close()

# import scipy.io as sio
# import numpy as np
#
# # # 将单个变量保存为mat文件, 同目录下就会有一个x.mat文件, 可以在matlab中打开了
# # x = [[1, 2, 3, 4], [5, 6, 7, 8]]
# # sio.savemat('x.mat', {'x': x})
# #
# # # 将多个变量保存为mat文件
# # a, b, c, d = 1, 2, 3, 4
# # sio.savemat('abcd.mat', {'a': a, 'b': b, 'c': c, 'd': d})
#
# # 读取mat文件
# abcd = sio.loadmat('k.mat')
# print(abcd)

这篇关于Python科研绘图20211129:伪彩色图的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!