matplotlib / matplotlib/basemap

contour and contourf produce conflicing results for certain projections

Abierto
#229 12 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
817
Forks
395
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Originally posted [here](http://stackoverflow.com/questions/33850052/matplotlib-why-inconsistent-results-between-contour-and-contourf) because I wasn't convinced it was a bug (I'm new to matplotlib)... but I'm increasingly convinced it is a bug, so here we are.

I'm plotting some NCEP temperature anomaly data using the stereographic projection. When I plot the data with filled contours, contourf, I see the first picture below. Note the red (positive values) over most of North America. When I change contourf to contour, making no other changes, I see the second picture below. Note the streak of blue (negative values) over central North America.
![demo1](https://cloud.githubusercontent.com/assets/8312113/11348506/37901804-91e4-11e5-96ba-b6b89c820a51.png)![demo2](https://cloud.githubusercontent.com/assets/8312113/11348509/3aa323e2-91e4-11e5-894c-0c40d1c3dcfa.png)
The contour result with the blue is what is actually in the data, and therefore what I expect to see. The contourf result is not what I expect. Is this a bug, or am I using these tools improperly? (Update: The first plot above should look like the below plot, which was produced using the cylindrical projection:)
![demo3](https://cloud.githubusercontent.com/assets/8312113/11348524/495ddf3a-91e4-11e5-8810-f284ebfbfb92.png)
The python code is reproduced below... you can obtain the data as a small binary file [here](https://onedrive.live.com/redir?resid=9F18EDDCF4E99E72!108&authkey=!ADXWQucUMyXgkJk&ithint=file%2cbin) if you want to try it yourself.

Some more notes... (1) shifting the longitude range to -180 to 180 using `addcyclic` and `shiftgrid` does not help. (2) the Lambert Conformal ('lcc') projection produces results that are _less_ wrong, but still not correct, when using contourf. (3) the Alberts Equal Area ('aea') projection centered on North America looks correct, however when I use the North Pole-centric version ('nplaea') I only see correct results for certain values of `lon_0`. I am happy to provide an example if this turns out to be a different issue.

```
import numpy as np
import matplotlib.pyplot as plt

# read data

f = open('data5.bin', 'r')
lat = np.fromfile(f,dtype=np.float32,count=73)
lon = np.fromfile(f,dtype=np.float32,count=144)
data = np.reshape(np.fromfile(f,dtype=np.float32,count=-1),(73,144))
f.close()

# plot

m = Basemap(width=10000000,height=6000000,
resolution='l',projection='stere',\
lat_ts=50,lat_0=50,lon_0=253)
m.drawcoastlines()
lon2d, lat2d = np.meshgrid(lon,lat)
x, y = m(lon2d,lat2d)
mymap = plt.contourf(x,y,data,levels=np.arange(17)-8,cmap=plt.cm.bwr)
plt.colorbar(mymap,orientation='vertical',shrink=0.75)
plt.show()
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza ejecutando el ejemplo de Python reproducido con data5.bin y comparando contourf y contour bajo la proyección estereográfica. Revisa cómo se pasan las cuadrículas x/y proyectadas a cada llamada de trazado y, después, compara los resultados cilíndricos, Lambert Conformal y Albers descritos en el issue. Se considera terminado cuando contourf coincide con los datos esperados, incluida la región de Norteamérica, sin cambiar los datos de entrada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
matplotlib, numpy, python
Área
data-visualization
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.