Forums

No module named 'matplotlib' in my view.py

Hi, I'm new to python and matplotlib. When I imported "matplotlib" in my views.py, it show the error "No module named 'matplotlib' ". Can anyone help? Thanks.

Here is my views.py:

from django.shortcuts import render

from django.http import HttpResponseRedirect, Http404

from django.core.urlresolvers import reverse

from django.contrib.auth.decorators import login_required

from .models import Topic, Entry

from .forms import TopicForm, EntryForm

@login_required

def topics(request):

from matplotlib import pyplot as plt

input_values = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]
plt.plot(input_values, squares, linewidth=5)

# Set chart title and label axes.
plt.title("Square Numbers", fontsize=24)
plt.xlabel("Value", fontsize=14)
plt.ylabel("Square of Value", fontsize=14)

# Set size of tick labels.
plt.tick_params(axis='both', labelsize=14)

plt.savefig('static/squres_plot12.png', bbox_inches='tight')
# plt.show()

"""Show all topics."""
topics = Topic.objects.filter(owner=request.user).order_by('date_added')
context = {'topics': topics}
return render(request, 'mysites/topics.html', context)

never mind -- I figured out already. I forget to install matplotlib into my virtural env. Thanks.

Glad you worked it out :-)