data = np.array(number_list)
self.fig = plt.Figure()
self.ax = self.fig.add_subplot(1,1,1)
N = data.max() + 5
self.ax.set_xlim(0,N)
self.ax.set_ylim(0,N)
self.ax.invert_yaxis()
self.ax.get_xaxis().set_visible(False)
self.ax.get_yaxis().set_visible(False)
self.ax.set_aspect('equal')
this = self.ax.scatter(data[:,1], data[:,0],color= 'black', marker = 's', s=3)
self.fig.colorbar(this, ticks=[-1, 0, 1],orientation='horizontal')
self.canvas = FigureCanvas(self, -1, self.fig)
self.toolbar = NavigationToolBar(self.canvas)
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.vbox.Add(self.toolbar,0,wx.EXPAND)
self.vbox.AddSpacer(25)
self.SetSizer(self.vbox)
self.vbox.Fit(self)
I have tried creating a colorbar ‘attached’ to a graph, however i get the error TypeError: You must first set_array for mappable. The graph is a matrix plot.
where am i going wrong??
The issue is in these lines. You have set all of the markers to be a fixed color, so a color bar does not make any sense. If you want to use the
colorbaryou need to set the color of the markers by mapping a scalar -> color as such:where
len(color_data) == len(data[:,0]and is a 1D array-like object.