matplotlib / matplotlib/basemap

Bug in contour x/y values filtering in mpl_toolkits/basemap/__init__.py ?

Ouverte
#265 12 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Python
Étoiles
817
Forks
395
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I have been trying to plot unstructured data with **contour** and **contourf**, using the **tri=True** parameter. It works fine with contourf, but **I get a huge traceback when using contour** on the same data.

```
[...]
File "/home/share/unix_files/cdat/versions/cdat_install_uv-2.1.0_x86_64_gcc4_13/lib/python2.7/site-packages/matplotlib-1.4.0-py2.7-linux-x86_64.egg/matplotlib/tri/triangulation.py", line 55, in __init__
self.triangles, self._neighbors = _qhull.delaunay(x, y)
ValueError: x and y arrays must have a length of at least 3
```

After spending some time in the python debugger, I have found out that indeed the x and y coordinate arrays passed to the triangulation function had a zero size (and therefore less than 3 elements) because they were empty! More digging helped me find a very suspicious way of filtering the x and y values in the contour(self,x,y,data,_args,_*kwargs) function

```
# for unstructured grids, toss out points outside
# projection limb (don't use those points in triangulation).
[...]
mask = np.logical_or(xself.xmax,y>self.xmax)
x = np.compress(mask,x)
y = np.compress(mask,y)
```

Why would y be compared to the values of xmin and xmax instead of ymin and ymax, and is the logical combination ok???

I think we want to keep the values where: **xmin<=x<=xmax AND ymin<=y<=ymax**. And the **mask has to be True where we want to keep the value, in np.compress**! This is a bit misleading because it works in the opposite way that masks work in np.ma ...

The contour function works fine if I replace the mask definition above with

```
mask = np.logical_and(np.logical_and(x>=self.xmin, x<=self.xmax),
np.logical_and(y>=self.ymin, y<=self.ymax))
```

Can somebody review this? And it may be wise to use a slightly less misleading name for the _mask_ variable. Maybe replace _mask_ with _select_xy_ok_?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans mpl_toolkits/basemap/__init__.py, au niveau de la logique de filtrage de contour(self, x, y, data, ...), puis comparez ses entrées avec le matplotlib.tri triangulation traceback. Examinez le filtrage des limites de coordonnées proposé et exécutez les tests contour ou contourf existants s’ils sont disponibles. C’est terminé lorsque contour gère les données non structurées signalées sans transmettre de tableaux de coordonnées vides à la triangulation.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
numpy, python
Domaine
data-visualization
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.