Python Subprocess: Too Many Open Files

I guess the problem was due to the fact that I was processing an open file with subprocess: Here the cmd variable contain the name of a file that has just been created but not closed. Then the subprocess.Popen calls a system command on that file. After doing this for many times, the program crashed … Read more

How to create a density plot in matplotlib?

Sven has shown how to use the class gaussian_kde from Scipy, but you will notice that it doesn’t look quite like what you generated with R. This is because gaussian_kde tries to infer the bandwidth automatically. You can play with the bandwidth in a way by changing the function covariance_factor of the gaussian_kde class. First, … Read more

bbox_to_anchor and loc in matplotlib

When bbox_to_anchor and loc are used together, the loc argument will inform matplotlib which part of the bounding box of the legend should be placed at the arguments of bbox_to_anchor. For example (I’ve simplified the command a bit), the three options below will produce different locations for your legend, The first command will put the … Read more