How to generate Cocoa-valued graph using matplotlib in Python on OS X (preferably Leopard)

I'm not sure what is going on under the hood, but here is my setup, code example and problem:

Setup:

  • snow leopard (10.6.8)
  • Python 2.7.2 (provide EPD 7.1-2)
  • iPython 0.11 (provided by EPD 7.1-2)
  • matplotlib (provided by EPD 7.1-2)

code example:

import numpy as np import pylab as pl x=np.random.normal(size=(1000,)) pl.plot(x) 

Problem:

I cannot use standard Mac OS X scripts to access the window generated by the plot command.

For example, I cannot Command - Tab to a window. Thus, if the window is outside another window, I need to point it at it! Command - W does not close it.

Obviously, this is unacceptable. It seems that maybe starting Lion instead of Leopard might fix this, but I haven't updated yet. I feel the problem is that iPython generates windows that in a sense are not completely Cocoa -aware, but I really know very little, so I'm not very sure about this hypothesis.

Therefore, any ideas on how to resolve or work around this problem will be greatly appreciated.

+4
source share
2 answers

From the description on the iPython page, it looks like Python is using Qt to generate the UI. This means that the windows it creates are definitely not Cocoa windows and will not act like them.

There is unlikely to be an easy solution to this problem.

+2
source

I experienced the same annoyance with installing Anaconda Python 2.7.10 on Mac OS X Yosemite 10.10.5. One solution I found was to change the backend on Mac OS X or Qt4Agg by creating a ~/.matplotlib/matplotlibrc with a line:

 backend: MacOSX 

or

 backend: Qt4Agg 

Now I can easily get into the chart window using the application switcher using Command - Tab and close it with Command - W.

0
source

Source: https://habr.com/ru/post/1369338/


All Articles