2016-10-31 1 views
2

Ich versuche, den Farbbalken-Bereich auf meinem Konturdiagramm von 0 bis 0.12 zu bearbeiten, ich habe ein paar Dinge ausprobiert, aber es hat nicht funktioniert. Ich bekomme den vollen Farbbalkenbereich bis zu 0,3, was ich nicht möchte.Python Min- und Max-Bereich für Farbbalken auf Matplotlib Contour Graph

Dies ist mein Code:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.tri as tri 
triang = tri.Triangulation(x, y) 

plt.tricontour(x, y, z, 15, colors='k') 

plt.tricontourf(x, y, z, 15, cmap='Blues', vmin=0, vmax=0.12,\ 
       extend ='both') 
plt.colorbar() 

plt.clim(0,0.12) 

plt.ylim (0.5,350) 

plt.xlim(-87.5,87.5) 

plt.show() 

x, y, z sind alle Arrays mit einer Spalte und große Anzahl von Zeilen

Sie einen Blick auf meine Graph hier nehmen:

enter image description here

Bitte helfen!

+0

Sorry, aber welches Modul das? Ist es Matplotlib? Bitte markieren Sie damit, um bessere Antworten zu erhalten – AbdealiJK

+0

Ja, es ist Matplotlib, danke dafür, dass ich es hinzugefügt habe. (Zum ersten Mal hier eine Frage stellen!) – Fatma90

+0

Was sind x, y und z? – DavidG

Antwort

0

Ich denke, die Frage ist in der Tat gültig. @ Fatma90: Sie müssen ein funktionierendes Beispiel bereitstellen, das in Ihrem Fall x, y, z liefert.

Wie auch immer, wir können selbst einige Werte erfinden. Das Problem ist also, dass vmin und vmax einfach von plt.tricontourf() ignoriert werden und ich dafür keine gute Lösung kenne.

hier jedoch ein Problem zu umgehen, manuell den wir levels

plt.tricontourf(x, y, z, levels=np.linspace(0,0.12,11), cmap='Blues') 

Einstellung Hier 10 verschiedene Ebene verwenden, die gut aussieht (ein Problem wäre schön tickmarks zu haben, wenn unterschiedliche Anzahl von Stufen verwendet werden).

ich bin ein praktisches Beispiel um den Effekt zu sehen:

import numpy as np 
import matplotlib.pyplot as plt 

#random numbers for tricontourf plot 
x = (np.random.ranf(100)-0.5)*2. 
y = (np.random.ranf(100)-0.5)*2. 
#uniform number grid for pcolor 
X, Y = np.meshgrid(np.linspace(-1,1), np.linspace(-1,1)) 

z = lambda x,y : np.exp(-x**2 - y**2)*0.12 

fig, ax = plt.subplots(2,1) 

# tricontourf ignores the vmin, vmax, so we need to manually set the levels 
# in this case we use 11-1=10 equally spaced levels. 
im = ax[0].tricontourf(x, y, z(x,y), levels=np.linspace(0,0.12,11), cmap='Blues') 
# pcolor works as expected 
im2 = ax[1].pcolor(z(X,Y), cmap='Blues', vmin=0, vmax=0.12) 

plt.colorbar(im, ax=ax[0]) 
plt.colorbar(im2, ax=ax[1]) 

for axis in ax: 
    axis.set_yticks([]) 
    axis.set_xticks([]) 
plt.tight_layout() 
plt.show() 

Dies erzeugt

enter image description here

+0

Vielen Dank, es hat funktioniert! :) – Fatma90

Verwandte Themen