Hello,
Iam using matplotlib to create a scatter plot and i have trouble in converting to exe. The error iam getting is

Traceback (most recent call last):
  File "portopti.py", line 8, in <module>
  File "matplotlib\pyplot.pyc", line 95, in <module>
  File "matplotlib\backends\__init__.pyc", line 25, in pylab_setup
ImportError: No module named backend_tkagg

Iam using python 2.7 and matplotlib 1.0.1. I tried the setup scripts in http://www.py2exe.org/index.cgi/MatPlotLib and all are giving the same error.

Is this problem only in 2.7 and matplotlib 1.0.1? Have anybody succeeded in converting matplotlib application to exe? If so, could you please tell me the versions you have used?

Can you post the code that leads to this error? It looks like an import directive hasn't been written correctly.

Or, have you modified matplotlib modules to make the importing directive fail?

import urllib2,csv
import datetime
from matplotlib.pyplot import figure,show #problem here??

from numpy import arange
import matplotlib.mlab as mlab
from matplotlib.dates import DateFormatter
#This is for scatterplot2
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure

Problem is in the imports used for drawScatterPlot1(). If i comment out the imports used for drawScatterPlot1() and the function, the exe is generated.

def drawScatterPlot1():
    global dailyReturns

    fig = figure()
    
    ax = fig.add_subplot(111)
       
    r = mlab.csv2rec("table.csv")
   
    ax.set_title("Daily Returns Scatter Plot",fontsize=14)
    
    # Set the X Axis label.
    ax.set_xlabel("Date",fontsize=12)
    
    # Set the Y Axis label.
    ax.set_ylabel("Daily returns",fontsize=12)
   
    xticks = [2002,2003,2004,2005,2006,2007,2008,2009,2010,2011]
    ax.set_xticks(xticks,minor=False)
    yticks = [-4,-3.5,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,3.5,4]
    ax.set_yticks(yticks,minor=False)    
            
    ax.scatter(r.date,dailyReturns,s=10,color='b')
    ax.fmt_xdata = DateFormatter('%Y-%m-%d %H:%M:%S')
    fig.autofmt_xdate()   
       
    show()  
        
def drawScatterPlot2():
    global dailyReturns
    r = mlab.csv2rec("table.csv")
    # Create a figure with size 6 x 6 inches.
    fig = Figure(figsize=(15,15))
    
    # Create a canvas and add the figure to it.
    canvas = FigureCanvas(fig)
    
    # Create a subplot.    
    ax = fig.add_subplot(111)
    
    # Set the title.
    ax.set_title("Daily Returns Scatter Plot",fontsize=14)
    
    # Set the X Axis label.
    ax.set_xlabel("Date",fontsize=12)
    
    # Set the Y Axis label.
    ax.set_ylabel("Daily Returns",fontsize=12)
    
    # Display Grid.
    ax.grid(True,linestyle='-',color='0.75')   
        
    yticks = [-4,-3.5,-3,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,3,3.5,4]
    ax.set_yticks(yticks,minor=False)
        
    ax.scatter(r.date,dailyReturns,s=10,color='blue');       
    
    # Save the generated Scatter Plot to a PNG file.
    canvas.print_figure("dailyreturns.png",dpi=50)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.