GraphicsContextBase instance has no attribute 'get_sketch_params' - python

Quite new to python and programming and tried to search for answers to matplotlib plots, but couldn't find answers to my question.
I use Spyder and have anaconda installed. Installed matplotlib but when i run simple plot commands I just get <"matplotlib.figure.Figure at 0x11090c18"> and no plot
If I run it in a dedicated python interpreter i just get an empty plot
The simple code is:
from matplotlib import pyplot as plt
plt.plot([1,2,3,4,5], [2,4,6,8,10])
plt.show()
Is this just the result of some stupid error I made in the installation process?
Hope someone can help med out

I think the error you're seeing is generated by a change the Matplotlib team did some months ago. I tried to fix it in Spyder 2.3.0/1 but maybe it's not working correctly.
To see a plot the code you need to run is
from matplotlib import pyplot as plt
plt.ion()
plt.plot([1,2,3,4,5], [2,4,6,8,10])
plt.show()
Notice the second line, that's what's needed to get interactive plots.

Related

plt.show() from matplotlib does not open a window

I know this question or a related one has been asked many times, but I still have not found a solution: I ssh -X into a linux machine, where I run a conda installation of ipython. After importing matplotlib, I generate a plot (e.g., plt.plot(1,1)) and I want to show the plot in a window, which is forwarded to my local machine with plt.show(). This used to work, but suddenly no longer does: plt.show() does nothing. I guess this is related to a conda update, which I did yesterday, since a conda list --revisions does not show any suspicious recent changes in my environment.
From similar posts, I guess this is related to the matplotlib backend. The default backend 'Agg' generates png's via plt.savefig, but does not produce a plot in its own window, in which I can zoom. I have not managed to change the backend, though:
In [7]: import tkinter
In [8]: import matplotlib
In [9]: matplotlib.use('TkAgg')
In [10]: import matplotlib.pyplot as plt
gives
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
I have tried various similar things but with no success. Any suggestions?
Thank you!

How matplotlib works?

I know this may sound like a nooby question but I am new to python and am trying to graph some stock data using pandas. I know this is not technically a programming question but do I need to install anything special for the graph to print or does it just graph in the IDE console? Or none of the above? Thanks in advance
Welcome to the world of python programming!
To graph using Matplotlib, first you would have to ensure it is installed in your system:
pip install matplotlib
And then import it into your code using
import matplotlib.pyplot as plt #import the plotting method in Matplotlib
Following this import and creating your plot, you can have your plot shown using
plt.show()

Seaborn Not Working from Script in Ubuntu

Python 2.7.12
matplotlib 1.5.1
Seaborn 0.8.0
Ubuntu 16.04, with the pip package manager.
I have tried running the codes in seaborn gallery.
They simply do not work when I run a script from terminal. They just say
"seaborn.axisgrid.FacetGrid object at 0x7fdfa554c1d0". Matplotlib works though.
Seaborn does work, however, from the jupyter notebook in my browser. But even then, the plots are really bland and simple, not many interactive customisation options. Nothing like the attractive, feature rich and aesthetically pleasing things you see on tutorials, or the gallery.
Can someone tell me what's wrong?
To show a plot, you need to call
plt.show()
where plt is import matplotlib.pyplot as plt.

Matplotlib doesn't show plots on Mac; plt.show() hangs on 'MacOSX' backend

As of late, I can't get my Matplotlib plots to show up. I have a very simple script:
import matplotlib.pyplot as plt
plt.plot([1,2,3])
but nothing ever shows up. If I include the line
plt.show()
then my Python process hangs.
In my ~/.config/matplotlib/matplotlibrc file I have
backend : MacOSX
interactive : True
I'm a little embarrassed to ask this question. I've been a Matplotlib user for many years and have never had this problem. I don't know where to begin to fix this problem. Help!
I'm using Matplotlib 2.0.0 with Python 3.5.2 from Anaconda.
The answer, as pointed out by #ImportanceOfBeingErnest is that the backend configuration for me wasn't working. I'm not sure if I need to install some additional libraries or not. I decided not to use the MacOSX backend and used the Qt5Agg backend. This worked just fine and I didn't have to install any new libraries.
I've just remove the line
interactive: True
enter code here
from my ~/matplotlib/matplotlibrc. It works fine with only backend: MacOSX using the plt.show() command.

Trying to get matplotlib/numpy to work. Have tried different solutions and out of ideas

I'm trying to run a basic matplotlib script to ensure that everything is working. The program is as follows:
import numpy as np
import matplotlib.pyplot as plt
x=np.arrange(0,5,0.1);
y=np.sin(x)
plt.plot(x,y)
But when I run "python a.py" in the terminal I am getting the error
that the numpy module has no attribute 'arrange'.
I uninstalled numpy and matplotlib and reinstalled them. First numpy, then matplotlib through the ubuntu repository but I am still getting this error. I can't figure out what is wrong. Am I getting an incomplete installation or something? I am using Ubuntu 14.04.
The method name is arange, not arrange.
Also, after using plt.plot(...), you need to call plt.show() to draw the plot.

Categories

Resources