ich habe folgenden Code für einen Contourplot mit pylab. Beim Plot sind die Bereiche weiß, bei denen x und y Werte nicht mehr gleichzeitig existieren. Kann mir jemand sagen, wie man diese weißen Bereiche im Plot "rausschneiden" könnte? Ich wäre sehr dankbar!
Das Problem liegt beim Plot. Der Code generiert eine Textdatei "square_deviation.txt", bei der X,Y und Z-Werte in Spalten stehen. Könnte man da irgendwie die Daten wieder rauslesen und einen Contourplot machen?
Code: Alles auswählen
from numpy import matrix
from numpy import linalg
import numpy as np
from numpy import *
from pylab import *
import scipy
#matrix with input values from Q-package simulations
A = matrix( [[-782,28,-445],[-743,38,-416],[-697,29,-376],[-707,36,-389],[-813,14,-466 ],[-796,20,-455],[-771,25,-439],
[-722,33,-406],[-698, 22,-373], [-699,29,-382], [-821,17,-471],[-808,23,-462],[-782,27,-445],[-743,36,-418],[-704,28,-382],
[-709,36,-393],[-768,25,-438],[-715,31,-403],[-699,20,-372],[-699,26,-381]])
#making a list with numbers smaller than 1
a2list = linspace(0.5, 0.6, 101)
b2list = linspace (0.2, 0.6, 101)
amin=0.0
bmin=0.0
chi2min=1e10
output = open('square_deviation.txt', 'w')
flist = []
for a in range (0,len(a2list)):
flist.append([])
for b in range (0,len(b2list)):
x = matrix([[a2list[a]], [b2list[b]], [-1]])
z=A*x # Matrix multiplication of A and x.
converttoArray_Square=asarray(z)**2
sum_sqrt_Elements = sqrt(converttoArray_Square.sum())
f= sum_sqrt_Elements
#append mode to add new data to a text file
output.write('{0:5f} {1:5f} {2:10f}\n'.format(a2list[a], b2list[b], f))
#append sum of squared elements with one combination of a and b to a list
flist[a].append(f)
if f < chi2min:
amin = a2list[a]
bmin = b2list[b]
chi2min = f
output.close()
array = scipy.array(flist)
matrix= asmatrix(array)
print 'Minimum at :', amin, bmin, chi2min
A, B = meshgrid(a2list,b2list)
figure()
levels = range(10, 200, 20)
cset1 = contourf(A, B,matrix, levels,
cmap=cm.get_cmap('jet', len(levels)-1),
)
cset2 = contour(A, B,matrix, cset1.levels,
colors = 'k',
hold='on')
for c in cset2.collections:
c.set_linestyle('solid')
cset3 = contour(A, B,matrix, (0,),
colors = 'g',
linewidths = 2,
hold='on')
title('Filled contours')
colorbar(cset1)
show()