matplotlib / matplotlib/basemap

Shiftdata breaks pcolormesh wrapping

未关闭
#183 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
817
派生
395
PR 合并指标
30 天内没有已合并 PR

描述

I have a data grid which spans the whole globe from -180 -> 180. pcolormesh can plot this OK if I have lon_0=0 in which case Basemap doesn't have to do any wrapping
pcolormesh_ok

However if I do this for lon_0=180 (where Basemap has to shift some data), I get the following incorrect plot:
pcolormesh_bad

The code I have used for this is (using 1.0.7):

    import numpy as np
    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    x = np.arange(-180, 190, 10)
    y = np.array([40, 50, 60])
    data = np.arange(72).reshape((2, 36))
    xv, yv = np.meshgrid(x, y)
    # Add an empty row and column of data so that the data is the same shape as X,Y
    wider_data = np.ma.zeros(xv.shape)
    for index, v in np.ndenumerate(data):
        wider_data[index] = data[index]
    for lon in (0, 180):
        map = Basemap(lon_0=lon)
        map.drawparallels(np.arange(-90, 90, 20), labels=[1, 1, 0, 1])
        map.drawmeridians(np.arange(-180, 180, 30), labels=[1, 1, 0, 1])
        map.pcolormesh(xv, yv, wider_data, latlon=True)
        map.drawcoastlines()
        plt.show()

I suspect that this problem is related to https://github.com/matplotlib/basemap/issues/182 because to get around that issue, I have had to add an empty row and column to the data. This should still be OK though, since that extra data should just be ignored (from the pcolormesh docs).

However, what actually happens is that the empty row gets moved around because shiftdata doesn't know it should ignore and so the plot is wrong.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行提供的 Basemap 1.0.7 pcolormesh 复现,并比较 lon_0=0 和 lon_0=180 的绘图。检查 pcolormesh 用于 wrapping 的 shiftdata 路径;当额外的行和列仍被忽略,且移位后的绘图与预期的全局网格匹配时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
matplotlib, numpy, python
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。