Python, Spyder IDE - matplotlib does not plot - python

I'm using:
Python 2.7.3
matplotlib 1.4.1
Spyder IDE 2.3.8
My code has to produce a chart (combination of bar and scatter) . First run on the code succeeds in that, however all following executions (both run or debug) produce just an empty chart with correct grid, label, and legend, but no bars not scatter plot. I have to close Python console and open a new one to get the correct plot, and then the story repeats. In debugger I can see that all the data for the chart is fine.
I also tried Wing IDE (ver 5.1.10-1), and the very same code works fine all the time.
I found some suggestions about setting console preferences in Spyder (ie set GUI backend to Qt4Agg, agg, TkAgg, MAcOSX, Inline and such - none of those had any effect)
I would appreciate any help with this, as I'd prefer to use Spyder.
Many thanks
P.S. I used an earlier version of matplotlib without any issues, but recently I had to update it to ver 1.4.1 to use some libraries in an unrelated software project.

Related

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.

sudden Qt error when using matplotlib on cmd

There are questions referring to this same error message, but the crucial difference is that I am not (deliberately) using Qt. I don't actually know what it is, and I am trying to run my program on cmd, not through any IDE. I have been using matplotlib without any problems until just now, when i suddenly got the error message:
This application failed to start because it could not find or load the Qt platform plugin "windows"
in "".
Available platform plugins are: direct2d, minimal, offscreen, windows.
Reinstalling the application may fix this problem.
here is a sample program which produces this error, although I suspect it is a consequence of the package being used, not the program
import matplotlib.pyplot as plt
nums = [1,2,3,4]
labels = ["one","two","three","four"]
colours, one, two = plt.pie(nums, labels=labels, autopct='%1.1f%%')
plt.legend(colours, labels, loc="best")
plt.axis('equal')
plt.show()
again, I installed matplotlib years ago, and have been using it just fine until now. Any help would be greatly appreciated.
edit: python version 3.7.1, matplotlib version 3.1.1
Ok, I just fixed it by upgrading matplotlib to version 3.2.1
not sure why that worked but hey

Not able to display altair charts in jupyter notebook

I am not able to display the charts on jupyter notebook. The same code displays on chrome in one laptop but does not work on chrome on other laptop.
I do not see any error or even a empty plot when I execute the code but get alt.Chart(...) in the output.
The version of altair and vega etc are same on both the laptops.
For 'altair' version of '4.1.0',
'vega' version of '3.4.0'
just do alt.renderers.enable('default') instead of
alt.renderers.enable('notebook')
If it works in one notebook and not another, there are a couple possibilities for what is going on:
your notebooks are connected to different kernels with different versions of Altair and/or its dependencies installed. Run the following
import sys
print(sys.executable)
to see if you're using the same Python executable in your environments. If the results are different, you can use Kernel -> Change Kernel in the Jupyter notebook menu to change to a kernel with a working Altair version.
If that's not the case, then it is likely that you have inadvertently enabled a different renderer in one of the notebooks, for example by running alt.renderers.enable('notebook'). In Altair 4.0, the default renderer should work out-of-the-box in both Jupyter notebook and JupyterLab. Either restart your kernel or run alt.renderers.enable('default') to restore the default.
The behavior above can happen if you have too old a version of IPython installed. See If the notebook displays on one laptop and not the other, it may be that the broken one has too old a version of IPython installed. See https://altair-viz.github.io/user_guide/troubleshooting.html#notebook-textual-chart-representation for more information on what to upgrade.
See Altair's Display Troubleshooting guide for more information.

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.

Using PyCharm I want to show plot extra figure windows

After installing Anaconda3 & PyCharm in new PC, I tried to test the same code as uploaded here
And I got a window like this.
But usually I use the plot window like this format (from google image search)
I think the first view is useful for checking all of the plots, but I'm already used to the second version, separated plot figure from PyCharm console, and I can use the control panel.
So I want to use PyCharm as in the second picture. How can I change my PyCharm settings to use the second version plot figure (extra window)?
That's because PyCharm is opening it in Sciview. Go to Settings => search for Python Scientific. Uncheck the (only) box Show plots in toolwindows. Restart PyCharm. It should work like a charm ;)
Related to my answer here.
According to this, you can manually change the backend to fix the issue:
matplotlib.use('Qt5Agg')
Credit to #ImportanceOfBeingErnest for digging up the thread.
You need first to check if you have Pycharm Community or Pycharm Professional.
You can plot in different windows just in case you have a professional version.
You can use seeting -> scientific python ( link : https://www.jetbrains.com/help/pycharm/matplotlib-support.html ).
Or, use matplotlib backends: Qt5Agg, Qt4Agg and TkAgg.
(https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004382380-Matplotlib-doesn-t-show-plots-in-new-window )
However, I can suggest you to download your plot in a file and close the window. So, you can have your plots in different windows.
Check out this code:
file = '___your path___'
... make your code for visualisation
plt.show()
plt.savefig(file+'\\fig.png')
plt.close('all')
I was having the same problem, and not resolving it by only switching off scientific mode. Just press Cmd + Shift + A or Ctrl + Shift + A and search python scientific, then click on it and deselect show plots in tool window, you should be all set now.

Categories

Resources