I have the following code: This results in the following plot: How can I move the legend outside of the plot? Answer According to mwaskom’s comment above, this is a bug in OS X. Indeed switching to another backend solves the issue. For instance, I put this into my matplotlibrc:
How can I create an abstract syntax tree considering ‘|’? (Ply / Yacc)
Considering the following grammar: This is my code using ply: How am I supposed to build an AST with the expression if I can’t access the operators? I could separate the functions like p_expr_plus, but in this case, I would eliminate operator precedence. The docs are not so helpful, since I’m a be…
Converting dictionary with known indices to a multidimensional array
I have a dictionary with entries labelled as {(k,i): value, …}. I now want to convert this dictionary into a 2d array where the value given for an element of the array at position [k,i] is the value from the dictionary with label (k,i). The length of the rows will not necessarily be of the same size (e.…
how to convert Python 2 unicode() function into correct Python 3.x syntax
I enabled the compatibility check in my Python IDE and now I realize that the inherited Python 2.7 code has a lot of calls to unicode() which are not allowed in Python 3.x. I looked at the docs of Python2 and found no hint how to upgrade: I don’t want to switch to Python3 now, but maybe in the future.
opencv – videowriter control bitrate
I have a working python script that uses the video writer from opencv. source https://gist.github.com/stanchiang/b4e4890160a054a9c1d65f9152172600 If i take in a file, and regardless of whether I simply pass the video frame through to the writer (effectively duplicating the file) or if i try to edit the frame,…
Changing the value of range during iteration in Python
Above the is the code which prints numbers from 0-7 if I use just print i in the for loop. I want to understand the above code how it is working, and is there any way we can update the value of variable used in range(variable) so it iterates differently. Also why it always iterates up to the initial k
What is the inverse of the numpy cumsum function?
If I have z = cumsum( [ 0, 1, 2, 6, 9 ] ), which gives me z = [ 0, 1, 3, 9, 18 ], how can I get back to the original array [ 0, 1, 2, 6, 9 ] ? Answer Short and sweet, with no slow Python loops. We take views of all but the first
How is __mro__ different from other double underscore names?
I stumbled upon this behavior for double underscore name that I don’t understand: I know about the name mangling for __name, which doesn’t apply for __name__ (more for overloading operator methods). __id__ behaves just like a regular class variable which can be accessed via Class name as well as i…
Histogram of my cam in real time
Im trying to show the histogram in real time from grayscale of my webcam, the problem is that histogram is not being update and my cam stop until i close histogram’s window. How can i fix this? I want to show the grayscale img from my webcam and its histogram in same time, is possible do that? Answer I …
How can I get descriptive statistics of a NumPy array?
I use the following code to create a numpy-ndarray. The file has 9 columns. I explicitly type each column: Now I would like to get some descriptive statistics for each column (min, max, stdev, mean, median, etc.). Shouldn’t there be an easy way to do this? I tried this: but this returns an error: TypeEr…