Error getting PySide to work with matplotlib - matplotlib

I am trying to make PySide work with matplotlib, and I have the same problem
described in this thread
Getting PySide to work with matplotlib
trying to launch the PySide + matplotlib example from
http://wiki.scipy.org/Cookbook/Matplotlib/PySide
I have got an error
win.setCentralWidget(canvas)
TypeError: 'PySide.QtGui.QMainWindow.setCentralWidget' called with wrong argument types:
PySide.QtGui.QMainWindow.setCentralWidget(FigureCanvasQTAgg)
Supported signatures:
PySide.QtGui.QMainWindow.setCentralWidget(PySide.QtGui.QWidget)
Adding of
matplotlib.rcParams['backend.qt4']='PySide'
did not help as well as
os.environ["QT_API"] = "pyside"
At the same time PyQt4 examples work.
I use Windows 7, and WinPython 2.7.5.1 (Python 2.7.5, PySide 1.1.2, matplotlib 1.2.1)
Thank you for help!

The problem was in Spyder.
Everything works in other python dev enviroments.
Jed post the solution on another thread just the next day after my question https://stackoverflow.com/a/17376655/2531821

Related

Can't plot inline in iPython shell (Terminal and VScode terminal window)

can anyone help me to understand, why my iPython shell does not plot inline and in an external window instead? I am not talking about Jupyter notebooks. I made that work. Any help is appreciated and highly welcome. Thank you ...
Of course I tried several sources to tackle my issues.
Stackoverflow: -> didn't work
matplotlib.org -> same
ipython docs -> same
several others suggested by Google -> same
(py310_env) Murat ~ % ipython
Python 3.10.0 (default, Nov 10 2021, 11:24:47) [Clang 12.0.0 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.1.1 -- An enhanced Interactive Python. Type '?' for help.
The following code will plot, but **not inline**:
In [1]: import matplotlib.pyplot as plt
In [2]: import numpy
In [3]: %matplotlib
Using matplotlib backend: MacOSX
In [4]: plt.plot([0,1,4,9,16])
Out[4]: [<matplotlib.lines.Line2D at 0x7f7821f3cfa0>]
I also tried this statement:
`%matplotlib inline´
if I try this one, then I get the following and not even an external display of the plot.
In [6]: plt.plot([0,1,4,9,16])
Out[6]: [<matplotlib.lines.Line2D at 0x7f7823002020>]
<Figure size 432x288 with 1 Axes>
I thought, that maybe my backend needs to be changed so. I tried I couldn`t even change it.
In [8]: %matplotlib qt
Warning: Cannot change to a different GUI toolkit: qt. Using osx instead.
In [9]: matplotlib tk
Warning: Cannot change to a different GUI toolkit: tk. Using osx instead.
Unless someone suggests a better solution, here is my cure.
Initially I had been trying to invoke ipython in the CLI using the command %ipython.
My conclusion is now, you need to use Jupyter Qt-console (available in the Anaconda distro. (Spyder, Jupyter and PyQT are preinstalled)
%jupyter qtconsole : QT will open up Terminal style console for Python and it does the inline plot magic.

Cannot use matplotlib library?

I am getting a weird error when calling any function with matplotlib.
import matplotlib as plt
plt.bar(np.arange(7, [1,3,2,1,4,6,1])
I get this error:
IPython.core.display.Javascript object
IPython.core.display.HTML object
Traceback (most recent call last): self.kernel.session.send(self.kernel.iopub_socket, msg_type,*
**AttributeError: 'NoneType' object has no attribute 'session'**
I have already tried:
upgrade my pip
upgrade matplotlib
installing pyplot (which brings error --> Non-zero exit code (1) --> Could not find a version that satisfies the requirement pyplot (from versions: ) No matching distribution found for pyplot)
My Matplotlib version = 3.3.3
OS --> Windows 10
Nothing seems to work and I am stuck. Do you have any idea why this is?
You are importing wrongly the library.
Usually one use
import matplotlib as mpl
(seldom used) or
import matplotlib.pyplot as plt
You are mixing the two imports/names, and so also the interface. Use the second import I wrote, for plt (pyplot).
Ho to debug? When you gain experience, you will learn that usually the problems are in your code and not on environment. So stop upgrading/reinstalling (often you worse the situation, see this site for examples). So try to debug your code. Check the matplotlib page of bar plots. Copy example, modify little things until you have your expected code. (Usually with such steps you find the error).

Tried to execute the easygui module in google colab but received no display name and no $DISPLAY environment variable

Links where I found solutions but don't understand:
no display name and no $DISPLAY environment variable in Jupyter Notebook
ipython notebook - $DISPLAY variable error
ipython notebook on linux VM running matplotlib interactive with nbagg
1. Summarize the problem
Want to study python with my son, we have book called Hello World Computer Programming for kids and other beginners. In chapter 6 we move toward create message boxes, button boxes, and choice boxes which will need to build our private app together.
2. Describe what you’ve tried
I looked at previous questions and learned that in order to import the module, I would have to first move the easygui.py file into my google drive. Then I learn to use [!pip install easygui] to install the module, which also worked. I was able to import the module without any problem but once the system reads the line of code to create the msg box it crashes and returns the message.
TclError: no display name and no $DISPLAY environment variable
I am completely clueless. I saw two similar situations but I'm new and I'm not sure how they solved this problem, they only listed that they used:
Your problem might be solved if you run before:
%matplotlib inline
My question is how and where did they do this because when i place this code before my only two lines a code i still get an error.
3. When appropriate, show some code
!pip install easygui
import easygui
easygui.msgbox("Hello There!")
and also with
%matplotlib inline
import easygui
easygui.msgbox("Hello There!")
easygui runs on local machine. So it's working when you write your lines in an editor, for example Python IDE or Sublime Text etc.
google-colab is an online platform, which is different from local (machine) environment. That's why on colab, it doesn't perform the pop-up.

PyQt5 Display Issue

I've asked pretty much the same question here before (I've since deleted it after getting no solutions), but one peculiarity has arose since then.
The following program:
import sys
from PyQt5 import QtWidgets, QtGui, QtCore
app = QtWidgets.QApplication([])
w = QtWidgets.QWidget()
w.setWindowTitle('Test')
w.show()
sys.exit(app.exec_())
does not produce a window, generates no errors, and continues to run until forcefully terminated. However, the same code does produce a window in the interactive interpreter.
I have repaired python; uninstalled, reinstalled, upgraded, and downgraded both python and PyQt including PyQt's other versions, as well as the dependencies any PyQt version requires. I am at a total loss as to what/where the problem is, especially since PyQt5 had worked properly before on the same machine.
Any help in fixing this would be immensely appreciated.

How to save PyPlot figures to video file in Julia?

I want to do something like the following using a loop and PyPlot to plot in figure windows. My question is how to save the figure windows to a movie file within the loop?
using PyPlot
for k=1:5
pcolormesh(rand(10,10))
if k==1; colorbar(); end
# save figure window to movie file here??
sleep(.5)
end
This is possible by directly using the animation submodule of matplotlib (the underlying Python library that PyPlot.jl wraps). However, it is painful; see e.g. the following notebook (in Spanish):
https://github.com/dpsanders/fisica_computacional/blob/master/como_animar.ipynb
The simplest way, however, seems to be using Plots.jl:
https://github.com/tbreloff/ExamplePlots.jl/blob/master/docs/pyplot_examples.md#functions-adding-data-and-animations.