Hello!
I’m trying to draw several plots on after the other in a wxScrolledPanel but I got the error message:
Traceback (most recent call last):
File “D:\Eigene Datein\Python\current\RNAiscan\Test\sample.py”, line 96, in <m
frame = MyFrame()
File “D:\Eigene Datein\Python\current\RNAiscan\Test\sample.py”, line 56, in __
init__
self.plot_data(self.fig)
File “D:\Eigene Datein\Python\current\RNAiscan\Test\sample.py”, line 90, in pl
ot_data
a = figure.add_subplot(id)
File “C:\python25\lib\site-packages\matplotlib\figure.py”, line 689, in add_su
bplot
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File “C:\python25\lib\site-packages\matplotlib\axes.py”, line 7207, in _init
···
_
raise ValueError( ‘Subplot number exceeds total subplots’)
ValueError: Subplot number exceeds total subplots
Here’s my code:
-- coding: latin1 --
import sys
import wx
import wx.lib.scrolledpanel as SP
from wx.lib.mixins.listctrl import CheckListCtrlMixin
from matplotlib.backends.backend_wx import FigureCanvasWx
from matplotlib.figure import Figure
import matplotlib.numerix as numpy
from pylab import array, arange, sin, cos, exp, pi, randn, normpdf, meshgrid,
convolve
d = {1: (’ Contig5535’, ‘230 ‘), 2: (’ Contig5534’, ‘3240 ‘), 3: (’ test’, ‘574’)}
class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin):
def init(self, parent):
wx.ListCtrl.init(self, parent, -1, style=wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES|wx.LC_SORT_ASCENDING)
CheckListCtrlMixin.init(self)
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
def OnItemActivated(self, evt):
self.ToggleItem(evt.m_itemIndex)
def OnCheckItem(self, index, flag):
data = self.GetItemData(index)
title = d[data][1]
if flag:
what = "checked"
else:
what = "unchecked"
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
self.panel = SP.ScrolledPanel(self, -1)
self.list = CheckListCtrl(self.panel)
self.list.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
vbox = wx.BoxSizer(wx.VERTICAL)
self.fig = Figure()
self.canvas = FigureCanvasWx(self.panel, -1, self.fig)
self.plot_data(self.fig)
vbox.Add(self.list,0, wx.EXPAND)
vbox.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
self.panel.SetSizer(vbox)
self.panel.SetAutoLayout(1)
self.panel.SetupScrolling()
self.list.InsertColumn(0, "ID")
self.list.InsertColumn(1, "Nr. of Hits")
for key, data in d.iteritems():
index = self.list.InsertStringItem(sys.maxint, data[0])
self.list.SetStringItem(index, 1, data[1])
#self.list.SetStringItem(index, 2, data[2])
self.list.SetItemData(index, key)
self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.list.SetColumnWidth(1, 100)
self.Show()
def plot_data(self, figure):
liste2 = ['Contig5535_range.txtcounts.txt', 'Contig5534_range.txtcounts.txt']
id = 111
for q in liste2:
f = open(q, 'r')
data = f.readlines()
liste3 = []
liste4 = []
for line in data:
line = line.strip()
x = line.split(" ")
liste3.append(int(x[0]))
liste4.append(int(x[1]))
a = figure.add_subplot(id)
a.plot(liste3,liste4)
id = id + 1
if name == ‘main’:
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show(True)
app.MainLoop()
Has someone an idea how to solve this?
Thank in advance
Stefanie