Matplotlip

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
danielf
User
Beiträge: 1
Registriert: Freitag 15. Oktober 2010, 13:11

Allerseits,

könnte mir jemand mitteilen, wie man mit basemap *quadratische* Grafikfiles oder daten-arrays mit in latlon gegebenen Eckkoordinaten auf
den Globus mapt (in einem "Map-Objekt" z.B.) und *dannach* bestimmt in welcher Projektion man sich das Ergebnis ausgeben lässt. Scheinbar alle Beispiele mit basemap machen es anders rum:
Erst Hintergrundkarte mit gewünschter Projektion erzeugen, dann die Datenpunkte *per Hand* auf die gewünschte
Projektion transformieren, und dann plotten. Das erfordert bei einem Projektionswechsel das eintippen neuer Transformationsformeln
und Kenntnis der Datenarrayauflösung.

Mir ist nicht einsichtig, warum der user per Hand die Koordinaten des Datenfiles transformieren muss, wenn der Globus und die Datenmatrix latlon-Eckpunkten vorliegen. Mit lat-lon-Datenarrays ist schliesslich jedem Punkt auf dem Globus ein Datenelement eindeutig zugeordnet. (Nur sehr nahe der Pole mag das etwas unhandlich werden.) Letztendlich sei es ja
Sinn einer map-toolbox sowas möglichst zu vermeiden.

Grüße
Daniel
Benutzeravatar
gkuhl
User
Beiträge: 600
Registriert: Dienstag 25. November 2008, 18:03
Wohnort: Hong Kong

Hallo Daniel und Willkommen im Forum,

ich habe dir gerade über die Matplotlib Mailinglist geantwortet:
Dear Daniel,

to give the corners of an array, some "matplotlib" plotting functions have the "extent" keyword, e.g. "contour" and "imshow". You can use this to put your data on the map. However, the functions of the "Basemap" class do not support this functionality. "Basemap.imshow" overwrites the "extent" keyword (see docstring). A workaround is to call "matplotlib.pyplot.imshow" instead, to draw on your "Basemap" map:
>>> map = Basemap(projection='...', ...)
>>> map.drawcoastlines()
>>> extent = reduce(lambda x,y: x+y, map([lon0,lon1],[lat0,lat1])
>>> matplotlib.pyplot.imshow(data, extent=extent)
You can also create an axes instance first, to have more control over your plot.

To your second question: Since the real globe is a 3d sphere with longitude and latitude and your image is a 2d map with x,y coordinates, you need some rule how to transform longitude and latitude to your x,y system. This rules are the different projections. The main idea of "basemap" is to help you with this projection by calling "x,y = map(lons, lats)". So, I guess your are using "basemap" wrong, if you have to change the coordinates *by hand*. If you need more help, you should give a small example where your problem occurs.

Best Regards,
Gerrit
Grüße
Gerrit


PS: Du bist hier sowohl im falschen Forum als auch im falschen Thema. Bitte erstelle bei deiner nächsten Frage ein neues Thema im passenden Forum des Boards. In diesem Fall wäre "Allgemeine Fragen" richtig. Wäre schön, wenn einer der Moderatoren es verschieben könnte.
Edit: Danke fürs verschieben.
Antworten