I am writing a program that reads three columns (one column containing the
weights, the other two containing the values I want to plot) from a file
containing the results from a MonteCarlo Markov Chain. The file contains
thousends of lines. Then create the 2D histogram and make contourplots. Here
is a sample of the code (I don't know if is correct, it's just to show what
import numpy as np
import matplotlib.pyplot as mplp
chain = np.loadtxt("chain.txt", usecols=[0,4,6]) #read columns 0 (the
weights), 4 and 6 (the data), from the file "chain.txt"
h2D, xe, ye = np.histogram2D(chain[:,1],chain[:,2], weights=chain[:,0])
#create the 2D histogram
x = (xe[:-1] + xe[1:])/2. #x and y values for the plot (I use the mean
of each bin)
y = (ye[:-1] + ye[1:])/2.
mplp.figure() #open the figure
mplp.contourf(x, y, h2D.T, origin='lower') #contour plot
As it is the contours are not smooth and they look not that nice. After days
of searches I've found three methods and tried, unsuccesfully, to apply them
1) 2d interpolation: I got "segmentation fault" (on a quadcore machine with
8Gb of RAM)
2) Rbf (radial basis functions): I got wrong contours
3) ndimage: it creates spurious features (like secondary peaks parallel to
the direction of the main one)
Before beginning with Python, I used to use IDL to plot, and there is a
function 'smooth' that smooth for you 2D histograms. I haven't found
anything similar for Python.
Does anyone have an idea or suggestion on how to do it?
Thank in advance
View this message in context: http://old.nabble.com/Smooth-contourplots-tp29253884p29253884.html
Sent from the matplotlib - users mailing list archive at Nabble.com.