[matplotlib-devel] spines with 'axes' positions show in wrong place?
Do the right and top spines display correctly when the position is set using 'axes' coordinates? import matplotlib.pyplot as plt import numpy as np fig = plt.figure() x = np.linspace(0,2*np.pi,100) y = 2*np.sin(x) ax = fig.add_subplot(1,1,1) ax.set_title('centered spines') ax.plot(x,y) ax.spines['right'].set_position(('axes',0.1)) ax.yaxis.set_ticks_position('right') ax.spines['top'].set_position(('axes',0.25)) ax.xaxis.set_ticks_position('top') ax.spines['left'].set_color('none') ax.spines['bottom'].set_color('none') fig.savefig('test.png',bbox_inches='tight') Notice that the top spine is 0.25 in axes coordinates, where 0 in the axes coordinates is the *top* of the picture, and positive goes up. I'd expect that 0.25 in axes coordinates be 25% from the bottom of the picture, or that the coordinates would be reversed for the top spine and the top spine would be positioned 25% from the top of the picture. Having it jump above the picture was a surprise. I noticed the same sort of issue for the right spine, as illustrated above as well. Of course, it may be that I'm just not understanding something... Thanks, Jason -- Jason Grout -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
[matplotlib-devel] Canvas HTML5 backend
Hi, I'm trying to work on the canvas javascript backend I found here [1]. I'm trying to add text but the canvas origin is at the top left, how can I transform the co-ordinates from the matplotlib to canvas? def draw_text(self, gc, x, y, s, prop, angle, ismath=False): ctx = self.ctx ctx.font = "12px Times New Roman"; ctx.fillStyle = "Black"; ctx.fillText("%r" % s, x, y) [1] http://bitbucket.org/sanxiyn/matplotlib-canvas/src/80e9abf6d251/backend_canvas.py Regards, Michael -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] spines with 'axes' positions show in wrong place?
jason-s...@creativetrax.com wrote: > Do the right and top spines display correctly when the position is set > using 'axes' coordinates? > Jason, This looks like a bug. I'll look into it. Please ping me in a few days if you haven't heard back. -Andrew -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Canvas HTML5 backend
On Tue, Sep 1, 2009 at 10:32 AM, Michael Thompson wrote: > Hi, > I'm trying to work on the canvas javascript backend I found here > [1]. I'm trying to add text but the canvas origin is at the top left, > how can I transform the co-ordinates from the matplotlib to canvas? > > def draw_text(self, gc, x, y, s, prop, angle, ismath=False): > ctx = self.ctx > ctx.font = "12px Times New Roman"; > ctx.fillStyle = "Black"; > ctx.fillText("%r" % s, x, y) > > [1] > http://bitbucket.org/sanxiyn/matplotlib-canvas/src/80e9abf6d251/backend_canvas.py The backend canvas should know its height, so height-y should transform from bottom to top -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Canvas HTML5 backend
2009/9/1 John Hunter : > On Tue, Sep 1, 2009 at 10:32 AM, Michael Thompson wrote: >> Hi, >> I'm trying to work on the canvas javascript backend I found here >> [1]. I'm trying to add text but the canvas origin is at the top left, >> how can I transform the co-ordinates from the matplotlib to canvas? >> >> def draw_text(self, gc, x, y, s, prop, angle, ismath=False): >> ctx = self.ctx >> ctx.font = "12px Times New Roman"; >> ctx.fillStyle = "Black"; >> ctx.fillText("%r" % s, x, y) >> >> [1] >> http://bitbucket.org/sanxiyn/matplotlib-canvas/src/80e9abf6d251/backend_canvas.py > > The backend canvas should know its height, so height-y should > transform from bottom to top Thanks, turns out to be a problem setting the size of the canvas element that the javascript is rendered into. If self.flipy is set then the text.py takes care of subtracting y from the height. Next problem is the text alignment, look OK on the right axis but wrong on the left I presume it's the alignment. The documentation says that s should be a matplotlib.text.Text instance and I can use s.get_horizontalalignment() but it seems that s is a unicode string. How can I find the alignment I should set on the text? Michael -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Canvas HTML5 backend
On Tue, Sep 1, 2009 at 12:57 PM, Michael Thompson wrote: > 2009/9/1 John Hunter : >> On Tue, Sep 1, 2009 at 10:32 AM, Michael Thompson wrote: >>> Hi, >>> I'm trying to work on the canvas javascript backend I found here >>> [1]. I'm trying to add text but the canvas origin is at the top left, >>> how can I transform the co-ordinates from the matplotlib to canvas? >>> >>> def draw_text(self, gc, x, y, s, prop, angle, ismath=False): >>> ctx = self.ctx >>> ctx.font = "12px Times New Roman"; >>> ctx.fillStyle = "Black"; >>> ctx.fillText("%r" % s, x, y) >>> >>> [1] >>> http://bitbucket.org/sanxiyn/matplotlib-canvas/src/80e9abf6d251/backend_canvas.py >> >> The backend canvas should know its height, so height-y should >> transform from bottom to top > > Thanks, turns out to be a problem setting the size of the canvas > element that the javascript is rendered into. If self.flipy is set > then the text.py takes care of subtracting y from the height. > > Next problem is the text alignment, look OK on the right axis but > wrong on the left I presume it's the alignment. > > The documentation says that s should be a matplotlib.text.Text > instance and I can use s.get_horizontalalignment() but it seems that s > is a unicode string. How can I find the alignment I should set on the > text? > > Michael > My understanding is that all the backends should use left-bottom alignment. Text alignment in matplotlib is handled by mpl itself (not by the backend), and for this to work, you have to define get_text_width_height_descent method correctly. The real question is how we know the metric of the font that will be used for rendering. I have little knowledge about the html canvas specification, but I presume that the situation is very similar to the svg case. Unless we embed the fonts (the svg backend has an option to embed the fonts as paths), I don't think it is possible to get it right. Again, I have little knowledge about html5 canvas thing, and I hope any expert out ther clarify this issue. -JJ ps. gnuplot seems to use embedded fonts for their html5 canvas backend (I haven't checked carefully but their demo output uses canvastext.js, originally from http://jim.studt.net/canvastext/) > -- > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > ___ > Matplotlib-devel mailing list > Matplotlib-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Canvas HTML5 backend
2009/9/1 Jae-Joon Lee : > My understanding is that all the backends should use left-bottom > alignment. Text alignment in matplotlib is handled by mpl itself (not > by the backend), and for this to work, you have to define > get_text_width_height_descent method correctly. > > The real question is how we know the metric of the font that will be > used for rendering. I have little knowledge about the html canvas > specification, but I presume that the situation is very similar to the > svg case. Unless we embed the fonts (the svg backend has an option to > embed the fonts as paths), I don't think it is possible to get it > right. I see firefox 3.5 (html5) has a method to measure the width of the text, I'll look at using this in a javascript function to render the text. https://developer.mozilla.org/en/Drawing_text_using_a_canvas#measureText%28%29 > > ps. gnuplot seems to use embedded fonts for their html5 canvas backend > (I haven't checked carefully but their demo output uses canvastext.js, > originally from http://jim.studt.net/canvastext/) yep noticed that, but didn't realize the significance of not using the built in canvas text drawing. Thanks, Michael -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Canvas HTML5 backend
On Tue, Sep 1, 2009 at 6:03 PM, Michael Thompson wrote: > I see firefox 3.5 (html5) has a method to measure the width of the > text, I'll look at using this in a javascript function to render the > text. I'm not sure if this helps. *Matplotlib* (not the browser) needs to know the size of the text when it creates plots. And the issue is that matplotlib does not know, in general, what font the browser will pick up for rendering. It seems that people are using @font-face embedding which are supported by newer version of firefox and safari. So, one option would be to use @font-face to specify (and provide) the fonts that are used when the plot is created by matplotlib. The other option is to embed the texts as paths as done in the svg banckend. Of course, there always is a font license issue. -JJ -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
[matplotlib-devel] Automatically make room for tick labels FAQ entry
In the FAQ, there is an entry about adjusting subplot parameters to make room for really long tick labels: http://matplotlib.sourceforge.net/faq/howto_faq.html#automatically-make-room-for-tick-labels I made the example a little more general and included a utility function that takes care of tick labels and other objects on all sides of the graph (the example only corrects for overflows on the left). This code might be nice to go into the FAQ. I've attached the code. Please use it if you think it is good. Thanks, Jason -- Jason Grout import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(10)) ax.set_yticks((2,5,7)) labels = ax.set_yticklabels(('really, really, really', 'long', 'labels')) # To test labels on the right side, uncomment below #ax.yaxis.set_ticks_position('right') def on_draw(event): import matplotlib.transforms as mtransforms figure=event.canvas.figure bboxes = [] for ax in figure.axes: bbox = ax.xaxis.get_label().get_window_extent() # the figure transform goes from relative coords->pixels and we # want the inverse of that bboxi = bbox.inverse_transformed(figure.transFigure) bboxes.append(bboxi) bbox = ax.yaxis.get_label().get_window_extent() bboxi = bbox.inverse_transformed(figure.transFigure) bboxes.append(bboxi) for label in (ax.get_xticklabels()+ax.get_yticklabels() \ + ax.get_xticklabels(minor=True) \ +ax.get_yticklabels(minor=True)): bbox = label.get_window_extent() bboxi = bbox.inverse_transformed(figure.transFigure) bboxes.append(bboxi) # this is the bbox that bounds all the bboxes, again in relative # figure coords bbox = mtransforms.Bbox.union(bboxes) adjusted=adjust_figure_to_contain_bbox(figure,bbox) if adjusted: figure.canvas.draw() return False def adjust_figure_to_contain_bbox(fig, bbox,pad=1.1): """ For each amount we are over (in axes coordinates), we adjust by over*pad to give ourselves a bit of padding. """ adjusted=False if bbox.xmin<0: fig.subplots_adjust(left=(fig.subplotpars.left-bbox.xmin*pad)) adjusted=True if bbox.ymin<0: fig.subplots_adjust(bottom=(fig.subplotpars.bottom-bbox.ymin*pad)) adjusted=True if bbox.xmax>1: fig.subplots_adjust(right=(fig.subplotpars.right-(bbox.xmax-1)*pad)) adjusted=True if bbox.ymax>1: fig.subplots_adjust(top=(fig.subplotpars.top-(bbox.ymax-1)*pad)) adjusted=True return adjusted fig.canvas.mpl_connect('draw_event', on_draw) plt.show() -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel