Python - networkx.read_pajek not working - python

I am working with python networkx and matplotlib.pyplot.
The code I am using is the following:
import networkx as net
import matplotlib.pyplot as plot
orgchart = net.read_pajek("ACME_orgchart.net")
net.draw(orgchart)
The code does not throw errors and runs fine but the graph that is supposed to appear, does not and I know the code runs fine because an icon appears in the dock which I am sure signifies the graph visualization software in python but the actual visualization does not appear . This code is from the book "Social network analysis for startups" if someone could please help me figure this problem out I would be really grateful.
I am using python 2.7.3, on mac osX, with networkx, matplotlib, numpy installed.

The problem was that my matplotlib was not being used in interactive mode. Hence when working with an interactive display I needed to also include the line: plot.show() at the end for the display to appear.
Further Information can be found at : http://networkx.lanl.gov/tutorial/tutorial.html

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.

Error message in python plot using skfuzzy package

I am running "Fuzzy Control Systems: The Tipping Problem" posted here as an example.It works fine but displays following error message in plots. I need your help to fix this. I searched everywhere without any success.
C:\Users\Home\anaconda3\lib\site-packages\skfuzzy\control\fuzzyvariable.py:122: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
fig.show()

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

Save matplotlib plot when running Python2 application on Linux server with no display

Is it possible to use matplotlib plot or a plotting tool similar to this, to save a plot in a python2 application to a file when there is no display on the server I'm working on?
Context:
I am sshing onto a server cluster running New Debian to run a series of large optimisations in Python. I'd really like to be able to save those optimisations as plots (eg. a file such as "opt-100.png") as well as the raw data. I am unable to do so as neither pylab nor matplotlib.pyplot can be imported because there's no display (ie. "RuntimeError: could not open display" is thrown by python when I try and import them).
I realise I am able to save the raw data and then scp that onto my local machine but due to the current configuration of my code that would be a lot of work!!
The backend for Matplotlib has to be set to use software rendering instead of hardware rendering. Try this before any matplotlib or pylab imports:
import matplotlib
matplotlib.use('Agg')

Python, Spyder IDE - matplotlib does not plot

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.

Categories

Resources