[Matplotlib-users] how to control space between ylabel and yticklabel?
Hi, all, I have a long ylabel that is displayed in two lines. Thus, the ylabel overlaps with yticklabels. Does anyone know how to control the space between ylabel and yticklabel? Thank you very much. Best, cj - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Starting troubles with matplotlib.
Hi, I am trying to use the simple test.py program to draw a stacked bar graph. My intention is eventually to shrink this into a sparkline. Both the sample program and the image output are attached. What I cannot understand is why the vertical bars don't align to the y-axis 0 point. Any help is appreciated. -shishir import matplotlib from pylab import * table = { '2007-07-30' : [0, 0, 0], '2007-08-06' : [8, 3, 0], '2007-08-13' : [12, 1, 7], '2007-08-20' : [13, 13, 6] , '2007-08-27' : [11, 8, 11], '2007-09-03' : [7, 6, 16], '2007-09-10' : [8, 3, 20], '2007-09-17' : [5, 3, 25], } colors = ['red', 'green', '#CFCFCF'] vals = table.keys() vals.sort() for i,interval in enumerate(vals): print "%s : %s : %d " % (str(interval) , table[interval], i) # opened if table[interval][0] > 0 : print "open: %d %d %d %d" % (i, i, 0, table[interval][0]) plot((i, i), (0, table[interval][0]), color=colors[0], linewidth=3.0,aa=False) # closed if table[interval][1] > 0 : print "closed: %d %d %d %d" % (i, i, 0, -table[interval][1]) plot((i, i), (0, -table[interval][1]), color=colors[1], linewidth=3.0,aa=False) # carry_over if table[interval][2] > 0 : print "carry: %d %d %d %d" % (i, i, table[interval][0], table[interval][2]) plot((i, i), (table[interval][0], table[interval][2]), color=colors[2], linewidth=3.0, aa=False) text(i, 0, str(i), size=4) #plot((-1,i+1),(1,1), color='gray', linewidth=0.25) plot((-1,i+1),(0,0), color='gray', linewidth=0.1) savefig('c:/temp/test.png') <>- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Capturing keydown events
I'm embedding a FigureCanvasWxAgg into a wx.Panel and binding key events to it: class MyPanel(wx.Panel) def __init__(self, parent, file, id=-1): wx.Panel.__init__(self, parent, style=wx.WANTS_CHARS | wx.NO_FULL_REPAINT_ON_RESIZE) #Set up the canvas self.figure = Figure((9,8),75) self.canvas = FigureCanvasWxAgg(self, -1, self.figure) self.subplot = self.figure.add_subplot(111) #Set up the toolbar self.toolbar = NavigationToolbar2Wx(self.canvas) tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wx.Size(fw, th)) #Set up figure manager self.figmgr = FigureManager(self.canvas, 1, self) self.canvas.Bind(wx.EVT_KEY_UP, self.__keyup) self.canvas.Bind(wx.EVT_KEY_DOWN, self.__keydown) def self.__keyup(self, evt): print 'key up' def self.__keydown(self, evt): print 'key down' The program successfully detects keydown events for just about every key with three major exceptions: wx.WXK_RETURN, wx.WXK_RIGHT, wx.WXK_LEFT. There may be other keys out there, but those three keys are the ones I need to process events for. I've tried subclassing FigureCanvasWxAgg and defining key_press_event (which doesn't seem to work) and overriding _onKeyDown (which still does not capture the keys I need). Something weird seems to be happening to these keys, and was wondering if anyone could help me? I am able to detect the EVT_KEY_UP for these three keys. Just not the key down ones. Thanks! Orest - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] py2exe with pylab
With the setup you provided. I could get py2exe to make an exe of the simple_plot.py from simple_plot_wxagg of py2exe examples. When I tried this on another python prog, I remarked that if I comment the following line : import matplotlib.backends.backend_wxagg the exe created by py2exe crash and the log tells us : Traceback (most recent call last): File "entropia.py", line 6, in File "pylab.pyo", line 1, in File "matplotlib\pylab.pyo", line 222, in File "matplotlib\backends\__init__.pyo", line 24, in pylab_setup ImportError: No module named backend_wxagg I think the same kind of problem may append with the default backend tkagg... - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plot different columns
Hi Jouni, Jouni K. Seppänen schrieb am 09/16/2007 05:51 PM: > Fabian Braennstroem <[EMAIL PROTECTED]> writes: > >> Lets say I have to columns, the I could use in a script: >> >>res=plot(array_mapped[:,0],array_mapped[:,1], 'b', >> array_mapped[:,0],array_mapped[:,2], 'g') >> >> The next time a have 5 columns in a file and want to plot all 5 >> columns without adjusting the 'plot' command in the script, but just >> by defining an argument when starting the script. > > Perhaps 'plot' is not the ideal interface for your purposes. How about > something like this: > > > > > > #!/usr/bin/env python > > import matplotlib > from matplotlib.lines import Line2D > import pylab > import numpy as npy > > def myplot(ax, matrix, linestyle, color): > for column in range(1, matrix.shape[1]): > line = Line2D(matrix[:,0], matrix[:,column], > linestyle=linestyle, color=color) > ax.add_line(line) > > colors = 'brk' > > for d in range(2,5): > fig=pylab.figure() > ax=fig.add_subplot(111) > matrix = npy.random.rand(d,d) > matrix[:,0] = npy.linspace(0, 1, num=d) > myplot(ax, matrix, '-', colors[d-2]) > > pylab.show() Thanks for your help! add_line seems to be the right function... I am not sure yet, if I need your function call, but I will check it!? Fabian - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Drawing filled circles (discs)
How about this solution? I'm a complete newbe, but this seems to do the trick. I didn't see a CircleCollection so I used CirclePolygon to generate vertices for a circle; these I grab and toss into a PolyCollection. Enjoy, Dave import matplotlib from matplotlib.patches import CirclePolygon from matplotlib.collections import PolyCollection import pylab fig=pylab.figure() ax=fig.add_subplot(111) N = 20 x = pylab.rand(N) y = pylab.rand(N) radii = 0.1*pylab.rand(N) colors = 100*pylab.rand(N) verts = [] for x1,y1,r in zip(x, y, radii): circle = CirclePolygon((x1,y1), r) verts.append(circle.get_verts()) p = PolyCollection(verts, cmap=matplotlib.cm.jet) p.set_array(pylab.array(colors)) ax.add_patch(p) pylab.colorbar(p) ax.axis('equal') pylab.show() -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jouni K. Seppänen Sent: Wednesday, September 19, 2007 11:03 AM To: matplotlib-users@lists.sourceforge.net Subject: Re: [Matplotlib-users] Drawing filled circles (discs) sidimok <[EMAIL PROTECTED]> writes: > Well, let's take the one you've proposed the last time. How than can i > put a colorbar beside the plot? Add in the imports from matplotlib.colorbar import ColorbarBase, make_axes and change the myscatter function to def myscatter(ax, colormap, x, y, radii, colors): for x1,y1,r,c in zip(x, y, radii, colormap(colors)): ax.add_patch(Circle((x1,y1), r, fc=c)) cax, _ = make_axes(ax) ColorbarBase(cax, cmap=colormap) A better solution is probably to implement a CircleCollection similarly to the other collections. -- Jouni K. Seppänen http://www.iki.fi/jks - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Drawing filled circles (discs)
sidimok <[EMAIL PROTECTED]> writes: > Well, let's take the one you've proposed the last time. How than can i put a > colorbar beside the plot? Add in the imports from matplotlib.colorbar import ColorbarBase, make_axes and change the myscatter function to def myscatter(ax, colormap, x, y, radii, colors): for x1,y1,r,c in zip(x, y, radii, colormap(colors)): ax.add_patch(Circle((x1,y1), r, fc=c)) cax, _ = make_axes(ax) ColorbarBase(cax, cmap=colormap) A better solution is probably to implement a CircleCollection similarly to the other collections. -- Jouni K. Seppänen http://www.iki.fi/jks - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Drawing filled circles (discs)
Jouni K. Seppänen wrote: > > > It would help to give a complete example. ColorbarBase itself does not > create a colorbar but is useful for drawing a colorbar in existing axes. > > Well, let's take the one you've proposed the last time. How than can i put a colorbar beside the plot? #!/usr/bin/env python import matplotlib from matplotlib.patches import Circle import pylab def myscatter(ax, colormap, x, y, radii, colors): for x1,y1,r,c in zip(x, y, radii, colormap(colors)): ax.add_patch(Circle((x1,y1), r, fc=c)) fig=pylab.figure() ax=fig.add_subplot(111) myscatter(ax, matplotlib.cm.jet, pylab.rand(20), pylab.rand(20), 0.1*pylab.rand(20), pylab.rand(20)) ax.axis('equal') pylab.show() -- View this message in context: http://www.nabble.com/Drawing-filled-circles-%28discs%29-tf4441651.html#a1276 Sent from the matplotlib - users mailing list archive at Nabble.com. - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Drawing filled circles (discs)
sidimok <[EMAIL PROTECTED]> writes: > It works just fine, however the colorbar I'm getting with the following > commands is very tiny. > > norm = matplotlib.colors.Normalize(vmin=x[0], vmax=x[-1]) # just an example > cb = matplotlib.colorbar.ColorbarBase(ax, cmap=matplotlib.cm.jet, norm=norm) It would help to give a complete example. ColorbarBase itself does not create a colorbar but is useful for drawing a colorbar in existing axes. -- Jouni K. Seppänen http://www.iki.fi/jks - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Drawing filled circles (discs)
Jouni K. Seppänen wrote: > > sidimok <[EMAIL PROTECTED]> writes: > >> I'm using matplotlib to draw (from matplotlib.Patches import Circle) >> filled >> circles (disks) from a formatted data file, and would give each disk a >> color relative to a variable, as done by the "scatter" function. > > Here's one way to do it: > > > #!/usr/bin/env python > > import matplotlib > from matplotlib.patches import Circle > import pylab > > def myscatter(ax, colormap, x, y, radii, colors): > for x1,y1,r,c in zip(x, y, radii, colormap(colors)): > ax.add_patch(Circle((x1,y1), r, fc=c)) > > fig=pylab.figure() > ax=fig.add_subplot(111) > > myscatter(ax, matplotlib.cm.jet, > pylab.rand(20), pylab.rand(20), 0.1*pylab.rand(20), > pylab.rand(20)) > > ax.axis('equal') > pylab.show() > > > > Hi! It works just fine, however the colorbar I'm getting with the following commands is very tiny. norm = matplotlib.colors.Normalize(vmin=x[0], vmax=x[-1]) # just an example cb = matplotlib.colorbar.ColorbarBase(ax, cmap=matplotlib.cm.jet, norm=norm) Any idea? Thanks guys. -- View this message in context: http://www.nabble.com/Drawing-filled-circles-%28discs%29-tf4441651.html#a12776069 Sent from the matplotlib - users mailing list archive at Nabble.com. - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users