Seite 1 von 1

Achenbeschriftung im Konturenplot

Verfasst: Donnerstag 9. November 2017, 09:22
von dot
Hallo an alle im Python-Forum!

Für meine Masterarbeit brauche ich viele schöne Konturenplots. Das klappt auch ganz gut. Nur die Achsenbeschriftung nicht. Ich möchte, dass die Zahlen an den Achsen den tatsächlichen Werten von x und y entsprechen. Ich habe es schon mit "plt.xticks(np.arange(-1, 1, 0.5))" probiert, was jedoch nicht klappt. Hier ist mein code:

Code: Alles auswählen

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

x = np.arange(-1.0,1.0,0.01)
y = np.arange(-1.0,1.0,0.01)
X,Y = np.meshgrid(x, y) # grid of point
Z=np.cos(3*X)*np.sin(3*Y)

im = plt.imshow(Z,cmap=cm.RdBu) # drawing the function with red and blue colourmap
plt.cset = plt.contour(Z,np.arange(-2.0,2.0,2.0),linewidths=2,cmap=cm.Set2)#adding the contour lines
plt.clabel(plt.cset,inline=True,fmt='%1.1f',fontsize=10)#labeling the contourlines
plt.colorbar(im)
plt.title("nice contourplot")
plt.show()
Als Neuling bin ich auch immer dankbar für allgemeine Hinweise und Verbesserungsvorschläge.

Vielen Dank für jede Hilfe!

Re: Achenbeschriftung im Konturenplot

Verfasst: Donnerstag 9. November 2017, 19:39
von narpfel
Moin,

`plt.imshow` kann man einen `extent` übergeben (eventuell muss auch ein `origin` gegeben werden), und wenn man `plt.contour` auch die `X`- und `Y`-Koordinaten übergibt, weiß das auch die Koordinaten der `Z`-Punkte.

Je nach Einsatzzweck ist vielleicht auch `plt.pcolormesh` einen Blick wert.

Re: Achenbeschriftung im Konturenplot

Verfasst: Samstag 11. November 2017, 16:23
von dot
Hallo narpfel,

dein Tipp ist hat super funktioniert:

Code: Alles auswählen

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

x = np.arange(-1.0,1.0,0.01)
y = np.arange(-1.0,1.0,0.01)
X,Y = np.meshgrid(x, y) # grid of point
Z=np.cos(3*X)*np.sin(3*Y)

im = plt.imshow(Z,extent=[-1,1,-1,1], cmap=cm.RdBu) # drawing the function with red and blue colourmap
plt.cset = plt.contour(X,Y,Z,np.arange(-2.0,2.0,2.0),linewidths=2,cmap=cm.Set2)#adding the contour lines
plt.clabel(plt.cset,inline=True,fmt='%1.1f',fontsize=10)#labeling the contourlines
plt.colorbar(im)
plt.title("nice contourplot")
plt.show()
Mit pcolormesh habe ichs auch probiert, aber irgndwie die Konturlinien nicht hineinbekommen... Aber so funktioniert es prima, also vielen Dank!

Tschüß und schönes Wochenende noch.