I am trying to plot a simple function in Python. I use the following code:
# lineplot.py
import numpy as np
import pylab as pl
# Make an array of x values
x = [1, 2, 3, 4, 5]
# Make an array of y values for each x value
y = [1, 4, 9, 16, 25]
# use pylab to plot x and y
pl.plot(x, y)
# show the plot on the screen
pl.show()
However, the last line in which I want to see the output results in the following error:
AttributeError: 'NoneType' object has no attribute 'get_default_size'
Does anybody have any idea where I'm going wrong?
Full traceback of the error:
>>> pl.show()
Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 394,\ in expose_event
self._render_figure(self._pixmap, w, h)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 75, in _render_figure
FigureCanvasAgg.draw(self)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 394, in draw
self.figure.draw(self.renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 798, in draw
func(*args)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 1946, in draw
a.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1017, in draw
tick.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 234, in draw
self.label1.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/text.py", line 526, in draw
bbox, info = self._get_layout(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/text.py", line 300, in _get_layout
ismath=False)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 180, in get_text_width_height_descent
font = self._get_agg_font(prop)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 226, in _get_agg_font
size = prop.get_size_in_points()
File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 798, in get_size_in_points
default_size = fontManager.get_default_size()
AttributeError: 'NoneType' object has no attribute 'get_default_size'
Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 394, in expose_event
self._render_figure(self._pixmap, w, h)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 75, in _render_figure
FigureCanvasAgg.draw(self)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 394, in draw
self.figure.draw(self.renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 798, in draw
func(*args)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 1946, in draw
a.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1017, in draw
tick.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 234, in draw
self.label1.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/text.py", line 526, in draw
bbox, info = self._get_layout(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/text.py", line 300, in _get_layout
ismath=False)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 180, in get_text_width_height_descent
font = self._get_agg_font(prop)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 226, in _get_agg_font
size = prop.get_size_in_points()
File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 798, in get_size_in_points
default_size = fontManager.get_default_size()
AttributeError: 'NoneType' object has no attribute 'get_default_size'
Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 394, in expose_event
self._render_figure(self._pixmap, w, h)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 75, in _render_figure
FigureCanvasAgg.draw(self)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 394, in draw
self.figure.draw(self.renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 798, in draw
func(*args)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 1946, in draw
a.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1017, in draw
tick.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 234, in draw
self.label1.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/text.py", line 526, in draw
bbox, info = self._get_layout(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/text.py", line 300, in _get_layout
ismath=False)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 180, in get_text_width_height_descent
font = self._get_agg_font(prop)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 226, in _get_agg_font
size = prop.get_size_in_points()
File "/usr/lib64/python2.7/site-packages/matplotlib/font_manager.py", line 798, in get_size_in_points
default_size = fontManager.get_default_size()
AttributeError: 'NoneType' object has no attribute 'get_default_size'
import matplotlib.pyplot as pl
instead ofimport pylab as pl
? – Hannes Ovrén Jan 7 at 20:40python -c 'import matplotlib; print(matplotlib.backends.backend)'
– Francesco Montesano Jan 7 at 20:53