- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 basemap 制作热量/强度图。我的输入是当时的一组纬度、经度和强度。数据集如下所示:
lat[0], lon[0] = intensity[0]
lat[1], lon[1] = intensity[1]
...
lat[n], lon[n] = intensity[n]
在每个索引处,纬度和经度对应于正确的传感器读数。我的代码看起来像这样:
fig = plt.figure(figsize=(10, 8))
# Set title
fig.suptitle("Intensities {} {}".format(start_time, stop_time))
# US Centered Map
map_axis = fig.add_subplot(111)
map = Basemap(
ax = map_axis,
lat_0 = 40, lon_0 = -95,
width = 6500e3, height = 6500e3,
projection = 'stere',
resolution = 'l'
)
map.drawcoastlines()
lats = ...
lons = ...
intn = ...
# Convert coordinates
lons, lats = map(lons, lats)
LONS, LATS = np.meshgrid(lons, lats)
map.pcolormesh(
LONS, LATS,
intn,
vmin = 0, vmax = 100
)
fig.savefig(file_name)
plt.close(fig)
此代码永远不会完成。我已经成功地自行绘制了 basemap 。 pcolormesh 是失败的。程序因此错误而崩溃。
$ ./plot_intensities.py
Running 2013-04-10 00:02:30 2013-04-10 00:02:45
Traceback (most recent call last):
File "./plot_intensities.py", line 151, in <module>
make_maps(samples)
File "./plot_intensities.py", line 144, in make_maps
make_map(bin_samples, start, walk)
File "./plot_intensities.py", line 117, in make_map
vmin = 0, vmax = 100
File "/usr/lib/python3/dist-packages/mpl_toolkits/basemap/__init__.py", line 521, in with_transform
return plotfunc(self,x,y,data,*args,**kwargs)
File "/usr/lib/python3/dist-packages/mpl_toolkits/basemap/__init__.py", line 3418, in pcolormesh
ret = ax.pcolormesh(x,y,data,**kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 1814, in inner
return func(ax, *args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py", line 5395, in pcolormesh
X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch)
File "/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py", line 4995, in _pcolorargs
numRows, numCols = C.shape
ValueError: not enough values to unpack (expected 2, got 1)
我了解到我的数据,第三个参数 intn
的格式不正确。我找不到任何关于如何制定该列表的文档。如何将其格式化为正确的形状?
谢谢。
最佳答案
如您所知,pcolormesh
用于通过创建二维数组的伪彩色图来绘制四边形网格。错误详细信息确实表明:在 numRows, numCols = C.shape
行,它期望 C
是一个二维数组,而 C
从ValueError:没有足够的值来解包(预期为2,得到1)来看,您提供的code>似乎是一个一维数组
。在我看来,您引入的数据集似乎只有对角线上的强度值(其中lat == lon
)。要获得颜色网格,您至少需要将强度数据扩展到二维数组并以某种方式填充缺失值。例如:
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
fig = plt.figure(figsize=(10, 8))
# Set title
fig.suptitle("Intensities {} {}".format('start_time', 'stop_time'))
# US Centered Map
map_axis = fig.add_subplot(111)
map = Basemap(
ax = map_axis,
lat_0 = 40, lon_0 = -95,
width = 6500e3, height = 6500e3,
projection = 'stere',
resolution = 'l'
)
map.drawcoastlines()
# Tried my best to simulate your data example. Don't be surprise if the result is ugly ...
nstep = 1
lats = np.arange(map.latmin, map.latmax, nstep)
lons = np.arange(map.lonmin, map.lonmax, nstep)
l = min(len(lats), len(lons))
lats = lats[:l]
lons = lons[:l]
intn = np.random.randint(0, 100, size=l)
# Convert coordinates
lons, lats = map(lons, lats)
LONS, LATS = np.meshgrid(lons, lats)
# The following 3 lines are just an example of the minimum you got to do before it works.
intn_array = np.zeros(LONS.shape)
for i in range(l):
intn_array[i, i] = intn[i]
intn = intn_array
map.pcolormesh(
LONS, LATS,
intn_array,
vmin = 0, vmax = 100
)
plt.show()
关于matplotlib - pcolormesh 的输入格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44894328/
我正在尝试使用 basemap 制作热量/强度图。我的输入是当时的一组纬度、经度和强度。数据集如下所示: lat[0], lon[0] = intensity[0] lat[1], lon[1] =
我正在尝试使用 basemap 制作热量/强度图。我的输入是当时的一组纬度、经度和强度。数据集如下所示: lat[0], lon[0] = intensity[0] lat[1], lon[1] =
我已经为此苦苦挣扎了一段时间。我有一组图像,我对这些图像的 X、Y 坐标执行一些数学运算,然后使用 pcolormesh 绘制新图像。我已经完成的所有计算,我所做的就是加载新的 X 和新的 Y,并使用
这是我的问题 抱歉表达困惑。 只需检查我的更新。更清楚了。 1。简介 3-d numpy 数组“数据”,形状为 (10, 31, 37)。 第一个维度 10 是二维数组的数量 最后 2 个数组表示二维
我想使用 matplotlib 的 pcolormesh 函数绘制颜色网格。但是,它会根据我是否指定坐标给出不同的结果。 import numpy as np from matplotlib impo
我需要将降雨汇总数据(来自卫星观测)绘制到 grib2 文件的 map 上。最后,我设法通过文本文件将数据加载到 numpy 数组中,并使用 basemap 将其与图片坐标联系起来。但问题是Pytho
当我使用 plt.pcolormesh(xx,cmap =xx) 时,无法设置绘图的最小值。 例如,我绘制一个二维数组数据,表示某个区域的人口密度。 http://i5.tietuku.com/89f
我有以下数据框,我将其绘制为矩阵: symbol abc def xyz symbol abc 1 0.2 0.5 def 0.2
我一直在尝试用 pcolormesh 做一个简单的热图,但我遇到了一些尺寸的奇怪效果,它添加了空的白色列。如果我创建一个 10x30,如下所示,它会完美运行。 from matplotlib impo
我正在尝试将一维数组绘制为 pcolormesh(因此颜色沿 x 轴变化,但对于每个 x 在 y 轴上保持不变)。但是我的数据有一些错误的值,所以我使用了一个屏蔽数组和一个屏蔽值设置为蓝色的自定义颜色
我正在尝试将颜色条添加到具有极坐标投影的 pcolormesh 图中。如果我不指定极投影,代码可以正常工作。在指定极坐标投影的情况下,会产生一个很小的图,并且没有颜色条。我在做一些愚蠢的事情,还是这是
我正在尝试使用 contour 显示带有轴标签的二维数据和 pcolormesh .正如在 matplotlib 用户列表中所指出的,这些函数遵循不同的约定:pcolormesh期望 x 和 y 值指
这个问题已经有答案了: How to color scatter markers as a function of a third variable (4 个回答) 已关闭 5 年前。 我有由两个(非
所以我尝试用 pcolormesh 绘制热图,并且我有带有值的数据。该数据范围为 0-500,但我希望色标本质上是对数的。基本上它应该看起来像这样: 热图数据位于 pcolormesh 中使用的 (x
我正在尝试使用 python 和 matplotlib 的 pcolormesh 绘制电子的概率(在氢原子中)。一切都很好,除了由于分布下降得如此之快 - 一些细节不可见,例如,径向函数的零点周围(在
我正在尝试绘制全局气溶胶光学深度 (AOD),其值通常约为 0.2,但在某些地区可以达到 1.2 或更高。理想情况下,我想绘制这些高值,而不丢失较小值的细节。对数刻度颜色条也不太合适,因此我尝试使用
我正在使用 pcolormesh 来显示我正在运行的某些算法的结果。我为一些 x_min、x_max 等创建了通常的网格,并定义了我的颜色图 h = (x_max - x_min) / 1000. x
我正在尝试映射具有相关纬度和经度的数据集。我正在使用的数据的详细信息如下: Variable Type Data/Info ------------------------------
我正在尝试运行最小二乘算法来将一条线拟合到我的数据中。 这段代码和我的问题类似; 'z' 是一个 50 in 50 矩阵,例如,我想通过功率大于 0.25 的数据拟合一条线。 (按幂表示右边的颜色条)
所以我试图绘制一个具有指定值的(125 x 1000)网格。我正在使用 matplotlib 和 pcolormesh。这就是我的代码的样子, enzyme 数组只是象征性的。 enzyme = np
我是一名优秀的程序员,十分优秀!