Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何绘制3个变量(深度、时间、参数)的热图_Python_Matlab_Plot_2d_Heatmap - Fatal编程技术网

Python 如何绘制3个变量(深度、时间、参数)的热图

Python 如何绘制3个变量(深度、时间、参数)的热图,python,matlab,plot,2d,heatmap,Python,Matlab,Plot,2d,Heatmap,我有随时间和深度变化的温度数据,见随附的示例图片。不过,我的实际数据集要大得多。我想知道如何绘制热图。我对Python或Matlab都持开放态度 谢谢 在MATLAB中 下面是一种使用meshgrid函数创建要绘制的温度域的方法。要绘制二维热图,我们可以使用surf并使用view功能将标高设置为90度俯视图。根据您是否希望进行插值,可以包括或删除着色插值的使用。要获得时间标签,我们可以将时间向量转换为字符串数组,并使用arrayfunc数组函数替换点。用冒号,:。最后,我们可以使用当前轴gca上

我有随时间和深度变化的温度数据,见随附的示例图片。不过,我的实际数据集要大得多。我想知道如何绘制热图。我对Python或Matlab都持开放态度

谢谢

在MATLAB中 下面是一种使用meshgrid函数创建要绘制的温度域的方法。要绘制二维热图,我们可以使用surf并使用view功能将标高设置为90度俯视图。根据您是否希望进行插值,可以包括或删除着色插值的使用。要获得时间标签,我们可以将时间向量转换为字符串数组,并使用arrayfunc数组函数替换点。用冒号,:。最后,我们可以使用当前轴gca上的set函数在绘图上显示新格式化的时间标签。颜色贴图可以设置为多种选项,如“热”、“冬”、“春”等


在python中使用MATLAB R2019b运行,如果您有矩阵形式的数据,如表,则可以使用matplotlib imshow函数。缺点是勾号标签将是列表中的位置,因此需要使用FuncFormatter选项传递函数以转换数据值中的列表位置。一个例子:

import numpy as np
import matplotlib.pyplot as plt

from matplotlib.ticker import FixedLocator, AutoLocator, FuncFormatter


#Just creating a sample data
dep = np.array([1,2,3])
time = np.arange(0,101)
dp,tm = np.meshgrid(dep,time)

matrix = np.flip(600*np.exp(-tm*dep/50),axis = 0)
#in this case we will have 3 columns, one for each depth

#ploting:
fig,ax = plt.subplots()

img = ax.imshow(matrix,cmap = 'OrRd',vmin = 0,vmax = 600,aspect = 'auto')

#set color bar
fig.colorbar(img,label = 'Temperature')

#Now we will correct the the x axis tick labels
ax.xaxis.set_major_formatter(FuncFormatter(lambda *x: x[0]+1))
#And fix the positions if you dont want tick labels like 2.5 wich are not in the data
ax.xaxis.set_major_locator(FixedLocator([0,1,2]))

ax.set_xlabel('Deph')

#correct the y axis tick labels
ax.yaxis.set_major_formatter(FuncFormatter(lambda *x: '%i'%(time[-1] - x[0])))
ax.set_ylabel('Time')

plt.show()

谢谢你,迈克尔。我还想问,我的体温在70到100之间。然而,颜色光谱的变化并不是那么深刻,因为我想它考虑的是0-100,例如红色到紫色的变化。如何获得70-100范围内的全彩色光谱?您希望有一个标准化为70-100范围内数据的颜色范围?
import numpy as np
import matplotlib.pyplot as plt

from matplotlib.ticker import FixedLocator, AutoLocator, FuncFormatter


#Just creating a sample data
dep = np.array([1,2,3])
time = np.arange(0,101)
dp,tm = np.meshgrid(dep,time)

matrix = np.flip(600*np.exp(-tm*dep/50),axis = 0)
#in this case we will have 3 columns, one for each depth

#ploting:
fig,ax = plt.subplots()

img = ax.imshow(matrix,cmap = 'OrRd',vmin = 0,vmax = 600,aspect = 'auto')

#set color bar
fig.colorbar(img,label = 'Temperature')

#Now we will correct the the x axis tick labels
ax.xaxis.set_major_formatter(FuncFormatter(lambda *x: x[0]+1))
#And fix the positions if you dont want tick labels like 2.5 wich are not in the data
ax.xaxis.set_major_locator(FixedLocator([0,1,2]))

ax.set_xlabel('Deph')

#correct the y axis tick labels
ax.yaxis.set_major_formatter(FuncFormatter(lambda *x: '%i'%(time[-1] - x[0])))
ax.set_ylabel('Time')

plt.show()