Unable to import FuncAnimation in python for matplotlib animation - python

I am trying to create an animation using matplotlib. This requires that I import FuncAnimation. When I run
from matplotlib.animation import FuncAnimation
I get the following error:
CalledProcessError: Command '['convert', '--version']' died with <Signals.SIGABRT: 6>.
I am not sure what the issue is. I am using matplotlib 3.1.2. Is there any way to address this issue? Your feedback would be greatly appreciated.

Related

How do I make matplotlib work in AWS EMR Jupyter notebook?

This is very close to this question, but I have added a few details specific to my question:
Matplotlib Plotting using AWS-EMR jupyter notebook
I would like to find a way to use matplotlib inside my Jupyter notebook. Here is the code-snippet in error, it's fairly simple:
notebook
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()
I chose this snippet because this line alone fails as it tries to use TKinter (which is not installed on an AWS EMR cluster):
import matplotlib.pyplot as plt
When I run the full notebook snippet, the result is no runtime error but also nothing happens (no graph is shown.) My understanding on one way this can work is by adding either of the following snips:
pyspark magic notation
%matplotlib inline
results
unknown magic command 'matplotlib'
UnknownMagic: unknown magic command 'matplotlib'
IPython explicit magic call
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
results
'NoneType' object has no attribute 'run_line_magic'
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'run_line_magic'
to my notebook which invokes a spark magic command which inlines matplotlib plots (at least that's my interpretation.) I have tried both of these after using a bootstrap action:
EMR bootstrap
sudo pip install matplotlib
sudo pip install ipython
Even with these added, I still get an error that there is no magic for matplotlib. So my question is definitely:
Question
How do I make matplotlib work in an AWS EMR Jupyter notebook?
(Or how do I view graphs and plot images in AWS EMR Jupyter notebook?)
The answer by #00schneider actually works.
import matplotlib.pyplot as plt
# plot data here
plt.show()
after
plt.show()
re-run the magic cell that contains the below, and you will see a plot on your AWS EMR Jupyter PySpark notebook
%matplot plt
As you mentioned, matplotlib is not installed on the EMR cluster, therefore such error will occur:
However, it is actually available in the managed Jupyter notebook instance (the docker container). Using the %%local magic will allow you to run the cell locally:
Import matplotlib as
import matplotlib.pyplot as plt
and use the magic command %matplot plt instead as shown in the tutorial here: https://aws.amazon.com/de/blogs/big-data/install-python-libraries-on-a-running-cluster-with-emr-notebooks/
The following should work:
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
Run the entire script in one cell
To plot something in AWS EMR notebooks, you simply need to use %matplot plt. You can see this documented about midway down this page from AWS.
For example, if I wanted to make a quick plot:
import matplotlib.pyplot as plt
plt.clf() #clears previous plot in EMR memory
plt.plot([1,2,3,4])
plt.show()
%matplot plt
%matplot plt
after plt.show() function works for me.
Try below code. FYI we have matplotlib 3.1.1 installed in Python3.6 on emr-5.26.0 and i used PySpark Kernel.
Make sure that "%matplotlib inline" is first line in cell
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()

Matplotlib plt.plot() not working in anaconda

I tried to run this code in spyder IDE of anaconda but it's not working
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5],[1,4,9,16,25])
plt.show()
The above code is returning error as follows:
TypeError: 'tuple' object is not callable
I am not able to figure out the problem.Please help
Not sure if this applies here but I had similar issues with matplotlib. From another Stackoverflow-answer this suggestion helped me:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
As said in the comments: the full error would help figuring out what really goes wrong.

matplotlib pyplot Invalid DISPLAY variable

While importing and attempting the following:
import matplotlib
from matplotlib import pyplot as plt
plt.plot([1,2,3],[1,4,9])
plt.show()
I get the following error. How do I fix? I am running Python 2.7, and notebook version 4.1.0. Thank you.
RuntimeError: Invalid DISPLAY variable
When running a jupyter notebook on a server, the server may not even be able to display the plot. The usual solution would be to use a non-interactive backend. In case of a jupyter notebook this would be done by adding
%matplotlib inline
at the top of the notebook, such that graphics are shown as png images.

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.

GraphicsContextBase instance has no attribute 'get_sketch_params'

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.

Categories

Resources