Can't close figure window using pylab from EPD - python

When I am using pylab in ipython notebook I try to close a figure and nothing happens except the toolbar with the pan and zoom options disappears. After this happens when I attempt to plot a new figure I get this:
PyAssertionError: C++ Assertion "wxAssertFailure" failed at ....\crc\msw\app.cpp(703) in wxAPP() Yield called recursively.
There is probably a lot of other output in the cmd window that I could post here as well if it helps. I've seen a solution to this problem here:
https://github.com/ipython/ipython/issues/3553/
Which was to set --pylab=wx when starting the notebook but this does not work for me. Does anyone have any ideas on how to solve this? I've been having a lot of trouble with EPD trying to get Cython to work with mingw as well...I wonder if somehow it's related. I ran the same code with my Anaconda distribution and I have no problems so I'm not quite sure where to begin on this one.

Related

`ipywidgets.interact` shows the widget itself but does not apply the function in the argument (Jupyter Notebook)

I have a problem that interactive objects from ipywidgets do not work in Jupyter Notebook on my computer. The widget itself is displayed but the function that it should control (e.g. drawing graph with changing parameter), seemingly, does not run. I took example from documentation and it does not work.
The picture of code and output
Code:
import ipywidgets
import widgetsnbextension
def greeting(text="World"):
print("Hello {}".format(text))
ipywidgets.interact(greeting, text="IPython Widgets")
What have I already tried:
There were similar questions, like this but the answer didn't work for me (the answer was to run this:
jupyter nbextension enable --py widgetsnbextension).
The code above works in GoogleColab so I tried to install their versions of packages ipython and ipykernel (packages ipywidgets and widgetsnbextensions were of the same version as mine). But it has led to errors so I have given up this idea. I have the latest versions of all packages now and I don't have Anaconda.
What should I try next? May be I am wrong and the problem has a different cause?
I found the answer!!!
I have had several nbextensions switched on (see screenshot). This was my mistake to include everything which seemed useful. When I turned off all nbextensions then all ipywidgets stuff started to work. Finally, I found that one particular extension called Limit Output is to be blamed for. Turn it off and all works fine.
The moral: don't use everything if you don't need it. Also, obviously, there is a bug in Limit Output extension because it is not supposed to affect widgets (it is supposed to limit output data when you accidentally write while(true) or something like that).
You can read some useful stuff about SageMath in the comments under the original question as well.

Matplotlib does not show plot in PyCharm on Mac

I am using PyCharm on my MacBook to code and now I wanted to make a simple plot. When I run the file via the usual 'Run' command (do not know what it is called), it nicely shows my plots, but when I run the file in the Python console (which I find more convenient because you can access your variables) it does not show anything. On the other hand, when I just type it in the Python console afterwards, it does work.
I have read some things about backends and other 'solutions' as I am apparently not the only one with this issue. Mine says macosx and gives the command: "Backend MacOSX is interactive backend. Turning interactive mode on." after running the file in the Python console. I tried changing the backend:
import matplotlib
# matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
but that does not work (no plot pops up). And yes, I use plt.show() after my plotting section :)
I also tried with 'QtAgg' but then I get: "ImportError: Failed to import any qt binding"
Now I am completely new to this backends stuff (I think it has to do with this), so I could really use some clear directions on how I can solve this issue.
Thanks in advance!
I am not sure we can solve this bug with some adjustment. I think you need to fresh start. I suggest you to start a new clean venv and install a new matplotlib there.

VS Code Interactive notebook

i can t use #%% anymore as a jupyternotebook cell. Its not marked as one or visuallized in any way. I tried reinstalling but didn t work.
I recently had a weird message which said something like "save code browsing activated" and casually just clicked away.
Any ideas how to get it back to normal?
I programm with #%% 99% of the time so i am kind of lost right now :D
regards martin
Check that you are in the right Python virtual environment, inside your VS Code. If you are in a virtual environment where you do not have the ipython packages installed, that would explain it.

matplotlib animations display axes but blank content

I'm trying to display the results of a simple function animated over time. There are many examples of this on matplotlib and stackoverflow (typical link below). All of these produce the same dysfunctionality: the axes appear, but the data doesn't: the content of the plot is blank. I'm literally copying and pasting tutorial code, so it seems likely to be a configuration issue, rather than a coding error.
A number of similar problems have been reported, but none of the answers seem to work. I'm on a current Mac with OSX 10.13.4, running python 3.6.5 and recently updated matplotlib. Per suggestions from other questions I've set up a Framework installation of python 3.6.5, straight from python.org. No change in behavior running outside or within a virtual environment (tried virtualenv and venv).
I haven't encountered problems with plots that don't attempt to animate - they work fine.
I've tried running many examples from the command line (bash), the PyCharm IDE, and in Jupyter, with same result (everything but animations works). There are no error messages except for examples that attempt to save images - those crash with a long error log (e.g. Animating "growing" line plot in Python/Matplotlib produces "ValueError: Invalid file object: <_io.BufferedReader name=65>" after pages of traceback). In such examples commenting out the save prevents the crash, but the plot remains empty.
Advice much appreciated.

Matplotlib won't let me savefig() and show() the same figure

After upgrading to Yosemite from Mountain Lion I've spent quite a bit of time getting all my packages working again, but I'm left with one weird issue. When I try to both save and show a matplotlib plot I get the following error:
Assertion failed: (s->stack->next != NULL), function CGGStackRestore, file Context/CGGStack.c, line 77.
The following short script produces this error, but works as expected if I comment out either the savefig or the show command.
import matplotlib.pyplot as pl
def main():
pl.plot(range(10),range(10))
pl.savefig('bugplot.jpg')
pl.show()
return
I'm using python 2.7, installed through homebrew, with my scipy, numpy and matplotlib packages all updated to the latest versions through pip. Saving a figure as well as showing it was working fine before I upgraded to Yosemite (and performed all the associated updates to xcode,homebrew,python,etc.), but I couldn't say exactly which versions I was using before. I can work around this problem of course, but it is bugging me, and I like getting a quick look at my figures while saving them, so any help would be much appreciated.

Categories

Resources