From edder at tkwsping.nl Sun May 14 10:45:45 2006 From: edder at tkwsping.nl (Edwin) Date: Sun, 14 May 2006 15:45:45 +0100 Subject: [Tioga-users] Plotting of function and 3d plots Message-ID: Hi, I've just started using your module and it seems very impressive. I've got a couple of questions/code. 1) I often plot functions, so I added some code that will let me plot functions directly. If the devs are interested in adding this functionality I would be more than happy to give my code. It is fairly simple, and basically allows you to write a plot method like this: def simple_function a = 1 f = Function.new { |x| a*x**2 } f.range(0, 10) t.show_plot(f.boundaries) { t.show_function(f, Silver) } end 2) I sometimes plot 3d data/functions. I kinda started looking into adding that functionality, but the problem is that show_polyline etc only take x, y coordinates. Am I correct that all low level drawing function (in Creating_paths.rb) are implemented in c? I guess I could create a class that wraps all these functions to recalculate the 3d coordinates to 2d on screen coordinates. Are you guys interested in adding 3d plotting and if so, what do you think is the cleanest way to go about that (I'd be happy to work on adding the code)? 3) I normally always convert my papers (tex) to dvi with texi2dvi and then to pdf with dvipdf, If I do that using plots created in tioga it complains about a missing boundingbox. Is there a way to fix that within Tioga creation or will I just have to convert the figures to (e)ps or start using pdflatex Edwin From paxton at kitp.ucsb.edu Sun May 14 12:47:46 2006 From: paxton at kitp.ucsb.edu (Bill Paxton) Date: Sun, 14 May 2006 09:47:46 -0700 Subject: [Tioga-users] Plotting of function and 3d plots In-Reply-To: References: Message-ID: <2DEE7F13-A346-46BE-A337-66B0263C615D@kitp.ucsb.edu> Hi Edwin, On May 14, 2006, at 7:45 AM, Edwin wrote: > Hi, > > I've just started using your module and it seems very impressive. > I've got > a couple of questions/code. > > 1) I often plot functions, so I added some code that will let me plot > functions directly. If the devs are interested in adding this > functionality I would be more than happy to give my code. It is fairly > simple, and basically allows you to write a plot method like this: > > def simple_function > a = 1 > f = Function.new { |x| a*x**2 } > f.range(0, 10) > t.show_plot(f.boundaries) { > t.show_function(f, Silver) > } > end That sounds like a nice addition. My hope all along has been that having Ruby as a base would enable just that kind of extension. Send the code, and I'll take a look at getting it into the release. Perhaps we need to set up a place for such add-ons: "Tioga Gems"? (see http://docs.rubygems.org/) > > 2) I sometimes plot 3d data/functions. I kinda started looking into > adding > that functionality, but the problem is that show_polyline etc only > take x, > y coordinates. Am I correct that all low level drawing function (in > Creating_paths.rb) are implemented in c? I guess I could create a > class > that wraps all these functions to recalculate the 3d coordinates to > 2d on > screen coordinates. Are you guys interested in adding 3d plotting > and if > so, what do you think is the cleanest way to go about that (I'd be > happy > to work on adding the code)? > I did briefly consider taking on 3D, but decided to focus on getting the Ruby-PDF-TeX combination for 2D working first. I think your idea of a separate 3D class that uses Tioga for 2D rendering would be a good way to go. It would be interesting to see if Tioga could serve as a base for doing various extensions -- Ruby certainly is a nice environment for that if you need to add C code for performance (as you undoubtedly would for 3D!). > 3) I normally always convert my papers (tex) to dvi with texi2dvi > and then > to pdf with dvipdf, If I do that using plots created in tioga it > complains > about a missing boundingbox. Is there a way to fix that within Tioga > creation or will I just have to convert the figures to (e)ps or start > using pdflatex. I suggest that it's time to make the switch to pdflatex. It seems to work (once you get a recent version installed!), and as you may have noticed from looking even a little at Tioga, I'm a firm believer in getting one option to work well and ignoring all the alternatives -- for example, I've even left out my baby, PostScript, in favor of PDF as the ONLY output representation. Perhaps I should change the Tioga icon to say "Ruby-PDF-PDFLaTeX" : - ) I look forward to hearing from you. Cheers, Bill From edder at tkwsping.nl Sun May 14 13:55:20 2006 From: edder at tkwsping.nl (Edwin) Date: Sun, 14 May 2006 18:55:20 +0100 Subject: [Tioga-users] Plotting of function and 3d plots In-Reply-To: <2DEE7F13-A346-46BE-A337-66B0263C615D@kitp.ucsb.edu> References: <2DEE7F13-A346-46BE-A337-66B0263C615D@kitp.ucsb.edu> Message-ID: > That sounds like a nice addition. My hope all along has been that > having Ruby as a base would enable just that kind of extension. Send > the code, and I'll take a look at getting it into the release. Perhaps > we need to set up a place for such add-ons: "Tioga Gems"? (see > http://docs.rubygems.org/) The code follows below. As I said it is quite simple, but I think it is nice to include. It basically just uses the block and the range to calculate a number of x and y coordinates (default 100). module Tioga class FigureMaker def show_function( function, color = nil, legend = nil) context do self.show_polyline( function.x, function.y, color, legend ) end end end class Tioga::Function attr_accessor :plotpoints def initialize( &block ) @f = block @xmin = 0.0 @xmax = 1.0 @plotpoints = 100 @xs = Array.new @ys = Array.new end def range( min, max ) @xmin = min.to_f @xmax = max.to_f calc end def boundaries calc return [@xs.min, @xs.max, @ys.max, @ys.min] end def width @xmax - @xmin end def x calc @xs end def y calc @ys end def calc #Check if this is the first time and/or some settings have been changed since last time if @xs.empty? || @ys.empty? || @xs.length != @plotpoints || @xs.first != @xmin || @xs.last != @xmax @xs = Array.new @ys = Array.new @xs[0] = @xmin @ys[0] = @f.call( @xs.first ) @step = width/(@plotpoints-1) (@plotpoints-1).times { |i| @xs[i + 1] = @xs[i] + @step @ys[i + 1] = @f.call( @xs[i + 1] ) } end end end end > I did briefly consider taking on 3D, but decided to focus on getting the > Ruby-PDF-TeX combination for 2D working first. I think your idea of a > separate 3D class that uses Tioga for 2D rendering would be a good way > to go. It would be interesting to see if Tioga could serve as a base > for doing various extensions -- Ruby certainly is a nice environment for > that if you need to add C code for performance (as you undoubtedly would > for 3D!). > I'll look into this (how to do it) and try to get something working. I'll just start with doing everything in ruby and worry about performance later. > I suggest that it's time to make the switch to pdflatex. It seems to > work (once you get a recent version installed!), and as you may have > noticed from looking even a little at Tioga, I'm a firm believer in > getting one option to work well and ignoring all the alternatives -- for > example, I've even left out my baby, PostScript, in favor of PDF as the > ONLY output representation. Perhaps I should change the Tioga icon to > say "Ruby-PDF-PDFLaTeX" : - ) Problem is that I switch from one thing to another when I hit a limitation of the other method, maybe someday I will find the ideal method for everything :) I hope Tioga will finally give me a clear/standard way of doing all my figures :) Edwin From edder at tkwsping.nl Thu May 18 06:55:58 2006 From: edder at tkwsping.nl (Edwin) Date: Thu, 18 May 2006 11:55:58 +0100 Subject: [Tioga-users] legend Message-ID: Hi, I've been using tioga more seriously for a couple of days now, and must say that in general it is very pleasant to work with. It also gives very nice looking plots and I think I will stick with this one, but ofcourse I have a few suggestions/questions :) First I dislike the way legends work at the moment (or misunderstand the way). If I call show_legend it will put the legend somewhere inside the plot area (inside the axes), but I seem to have no control over its place. With the show_plot_with_legend I get control over its placement, but it screws the aspect ratio of my plot (even when I put the legend inside the plot). I need to set the aspect ratio to about 1.2 to get a square plot. Ideally I could just call show_legend({'x'=>) etc. Secondly it would be nice if I could set the aspect ratio of the axes instead of the whole plot, that way I could put the plot in a subfigure and still be sure of the correct aspect ratio. (this would also fix the show_plot_with_legend issue.) Cheers, Edwin From paxton at kitp.ucsb.edu Thu May 18 11:41:25 2006 From: paxton at kitp.ucsb.edu (Bill Paxton) Date: Thu, 18 May 2006 08:41:25 -0700 Subject: [Tioga-users] legend In-Reply-To: References: Message-ID: <7C14FAAC-E559-4794-91CD-5E202638DFC2@kitp.ucsb.edu> Hi Edwin, On May 18, 2006, at 3:55 AM, Edwin wrote: > Hi, > > I've been using tioga more seriously for a couple of days now, and > must > say that in general it is very pleasant to work with. It also gives > very > nice looking plots and I think I will stick with this one, but > ofcourse I > have a few suggestions/questions :) Glad you are using it -- and especially glad you have suggestions for making it better! > > First I dislike the way legends work at the moment (or > misunderstand the > way). If I call show_legend it will put the legend somewhere inside > the > plot area (inside the axes), but I seem to have no control over its > place. > With the show_plot_with_legend I get control over its placement, > but it > screws the aspect ratio of my plot (even when I put the legend > inside the > plot). That needs to be fixed! The 'show_plot_with_legend' code is just a wrapper for lower level stuff. The actual drawing of the legend is done by a sequence that goes like this: set_subframe, rescale, show_legend. The legend is of course done after the plot, and 'show_plot_with_legend' does the plot as a subplot so that it will be done in its own graphics context. I think the main source of the aspect ratio problem is that the plot_scale for show_plot_with_legend defaults to 0.9 rather than 1.0 even when the legend is going inside. To fix this either add an explicit arg to set the scale to 1when you call show_plot_with_legend, or change the default (by adding t.legend_defaults['plot_scale'] = 1 to your initialization). Here's the modified example for legend inside from samples/plots.rb. I changed 'plot_scale' to 1, and now the aspect ratio is the same with or without the legend. -------------- next part -------------- A non-text attachment was scrubbed... Name: Reds_and_Blues_0044.pdf Type: application/pdf Size: 10320 bytes Desc: not available Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060518/6911a3b3/attachment-0002.pdf -------------- next part -------------- A non-text attachment was scrubbed... Name: Legend_Inside_0044.pdf Type: application/pdf Size: 10432 bytes Desc: not available Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060518/6911a3b3/attachment-0003.pdf -------------- next part -------------- HOWEVER --- unfortunately, just adding the plot_scale wasn't quite enough! I also had to move the legend to the left a little. In the original location of the legend, Tioga was overestimating the text bounding box and the overall width for calculating the aspect ratio was incorrectly growing a bit causing the aspect ratio to change a bit. This problem is a result of Tioga not knowing the exact text size that TeX will ultimately use (we don't even know what font TeX will use!)... Another cause of this problem is that text done by TeX is placed on top of the graphics, and therefore is not clipped to the inside of the plot frame. (Text done by PDF is part of the graphics, and it of course gets clipped.) I need to think a bit about how to deal with this -- perhaps legend text placed inside the frame shouldn't update the plot bounding box, whereas legend text outside should. Or perhaps I'm just being overly cautious about making a too generous estimate of the possible size of the text and that could be fixed instead. I'll think about it. > > Secondly it would be nice if I could set the aspect ratio of the axes > instead of the whole plot, that way I could put the plot in a > subfigure > and still be sure of the correct aspect ratio. Good idea! But we'll need to have a way to specify how to place the subplot with it's fixed aspect ratio inside the region that the 'super plot' has assigned it which can have a different aspect ratio. This could probably best be done with horizontal and vertical 'reference points' specified as a fractional distance along the subplot width/height and a corresponding fractional location along the width/height of the space that's been allocated for the subplot by its parent. I'll add it to my list! Let me know if there are issues here I'm overlooking. And thanks again for helping to make Tioga better. Cheers, Bill From paxton at kitp.ucsb.edu Thu May 18 14:44:30 2006 From: paxton at kitp.ucsb.edu (Bill Paxton) Date: Thu, 18 May 2006 11:44:30 -0700 Subject: [Tioga-users] legend (part 2) In-Reply-To: References: Message-ID: Hi Edwin, On May 18, 2006, at 3:55 AM, Edwin wrote: > Secondly it would be nice if I could set the aspect ratio of the axes > instead of the whole plot, that way I could put the plot in a > subfigure > and still be sure of the correct aspect ratio. (this would also fix > the > show_plot_with_legend issue.) Here's something to consider that might work for your setting the aspect ratio issue. Currently, when you call set_aspect_ratio, it creates a subframe within the current frame that has the requested ratio of width to height with respect to the parent frame. That's the key. The default assumption is that you work in logical coordinates relative to your parent. In the 'legend outside' case, the default is for the plot to get squeezed horizontally to make room for the legend -- thereby changing the aspect ratio. So even if the plot starts out by requesting an aspect ratio of 1, you get a squeezed plot when you add a legend since that is interpreted as 1:1 with respect to a squeezed parent frame. BUT, what you're saying you'd really want is to set the aspect ratio in physical (page) coordinates rather than in the parent frame coordinates. And of course you can do that using the coordinate conversion routines! Here's how: def set_physical_aspect_ratio(width_to_height) wd = t.convert_frame_to_page_dx(1) ht = t.convert_frame_to_page_dy(1) t.set_aspect_ratio(width_to_height * ht / wd) end Now if I add a call to set_physical_aspect_ratio(1) at the start of my plot, then it will stay square even if I add an outside legend (in that case the plot will shrink uniformly to make room for the legend rather than just horizontally). Here are some before and after examples, again using the Reds and Blues from samples/plots.rb again. 1) OLD WAY: Legend-inside vs. legend-outside the old way with aspect ratio relative to parent frame: ?? 2) NEW WAY: Legend-inside vs. legend-outside the new way with aspect ratio set relative to physical coordinates of page: ?? In the 2nd case, the plot routine is calling set_physical_aspect_ratio (1) while in the 1st case it is just taking whatever it gets from its parent frame. We may need to do more to get the default behavior to be better, but at least it is encouraging that the hooks seem to be there in Tioga to create work arounds! Cheers, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0005.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: Legend_Inside_0044.pdf Type: application/pdf Size: 10434 bytes Desc: not available Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0004.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0006.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: Legend_Outside_0044.pdf Type: application/pdf Size: 10047 bytes Desc: not available Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0005.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0007.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: Legend_Inside_0044.pdf Type: application/pdf Size: 10434 bytes Desc: not available Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0006.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0008.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: Legend_Outside_0044.pdf Type: application/pdf Size: 10066 bytes Desc: not available Url : http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0007.pdf -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060518/5cef73c7/attachment-0009.htm From edder at tkwsping.nl Sun May 28 09:48:49 2006 From: edder at tkwsping.nl (Edwin) Date: Sun, 28 May 2006 14:48:49 +0100 Subject: [Tioga-users] 3d axes Message-ID: Hi, I've been working (slowly) on adding 3d plotting capabilities to tioga. Till now I've jut plotted a line to represent every axis, but was wondering about the best way to get proper axes. As far as I can tell the standard axis drawing routines of tioga only allow to draw them horizontal or vertical etc. Would it be possible to have a routine that accepts a starting point and an ending point and draws an axis complete with ticks+labels etc between those? I must say that all the possiblilities with tioga are quite amazing when you start digging deeper, so if this already exists within the current codebase then please forgive me and point me in the right direction :) Edwin From edder at tkwsping.nl Tue May 30 15:43:52 2006 From: edder at tkwsping.nl (Edwin) Date: Tue, 30 May 2006 20:43:52 +0100 Subject: [Tioga-users] 3d axes In-Reply-To: <447C5724.7040100@9online.fr> References: <447C5724.7040100@9online.fr> Message-ID: On Tue, 30 May 2006 15:31:00 +0100, Vincent Fourmond wrote: > Cool! Thanks :) At the moment I've got a FigureMaker3d class which provides mainly a transform_coord function and wraps a couple of other functions (show_polyline, show_plot). Everything that it doesn't understand is send to the real figuremaker class with const_missing and method_missing. I might add some "magic" to method_missing so that it will detect when something has 3d coordinates (xs,ys,zs) convert those and send the result to the same FigureMaker.method. This detection might lead to some false positives though, so another possible method is to assume that every method that ends with 3d/3D (show_polyline3d) has xs,ys,zs data -> convert those and send them to the method of the same name, but without 3d behind it. Now I talk about it I think I like the second method :). How does append_points_to_path_3d sound? :) Most work till now has gone into a function3d class and a show_function3d method, which shows a surface and meshes, but they are not ideal yet. > Either Bill or I will have a look into as soon as possible, which is > not that soon (I'm quite busy and Bill is away from home for now). Ok thanks, I might throw something together in ruby myself, but that will also take some time. > I was thinking about creating a Tioga::Utils module where we could put > all kinds of classes or functions that help making simple things easier; > some of the code you already did post here should probably end up there. > What do you think ? It might be good to make something separate. To be honest the way tioga works with one _big_ figuremaker class is a bit counterintuitve for my ruby eyes :) I would probably have made a lot of different classes. You would get something like plot = Plot.new l = Line.new l.show( plot ) On the other hand it currently works and because everything is tightly integrated it might be a better/easier/quicker solution. My method of working means that I make a lot of small helper classes (right now I added for example an Angle class, which converts from deg to rad etc) that should go somewhere I guess :) Edwin P.S. I've been sending most mails to the user list, but you seem to reply in person. Should I email you guys directly or keep using the user mailing list. From edder at tkwsping.nl Wed May 31 07:47:54 2006 From: edder at tkwsping.nl (Edwin) Date: Wed, 31 May 2006 12:47:54 +0100 Subject: [Tioga-users] 3d axes In-Reply-To: References: <447C5724.7040100@9online.fr> Message-ID: On Wed, 31 May 2006 01:50:10 +0100, Alex Gutteridge wrote: > Sorry to butt in here, but I'd just thought I'd mention that I've been > thinking along the same lines. Although I really like the flexibility > and pretty output from Tioga, there's quite a learning curve, even if > you just want to do simple things. A ::Helper or ::Utils module that > could hide away some of the details would be nice to have. Unfortunately > I'm going to be away for the next two weeks, but I'd be happy to help > out when I get back. Something that I've been thinking about is a simple plot method that just plots a couple of dvectors/arrays and automatically opens the pdf file. I've created one of those to use gnuplot before, but it would be nice to be able to use tioga. Utils::plot( [xs,1 ys1], [xs2, ys2] ) Edwin From roy at mayfield.name Wed May 31 11:50:37 2006 From: roy at mayfield.name (Roy Mayfield) Date: Wed, 31 May 2006 08:50:37 -0700 Subject: [Tioga-users] 3d axes In-Reply-To: References: Message-ID: <200605310850.37323.roy@mayfield.name> > wrote: > > Sorry to butt in here, but I'd just thought I'd mention that I've > > been thinking along the same lines. Although I really like the > > flexibility and pretty output from Tioga, there's quite a learning > > curve, even if you just want to do simple things. A ::Helper or > > ::Utils module that could hide away some of the details would be > > nice to have. Unfortunately I'm going to be away for the next two > > weeks, but I'd be happy to help out when I get back. > > On Wednesday 31 May 2006 04:47, Edwin wrote: > Something that I've been thinking about is a simple plot method that > just plots a couple of dvectors/arrays and automatically opens the > pdf file. I've created one of those to use gnuplot before, but it > would be nice to be able to use tioga. > > Utils::plot( [xs,1 ys1], [xs2, ys2] ) > I asked Bill about the same thing last summer, and he gently noted that that is really easy to do in a ruby script (simpler than his examples). It took me awhile to get used to the make_preview_pdf() method, but I now agree with him and suggest that Tioga's code space be guarded for tough tasks (like your 3D idea, Edwin, which is really cool). -- Roy Mayfield From edder at tkwsping.nl Wed May 31 12:25:39 2006 From: edder at tkwsping.nl (Edwin) Date: Wed, 31 May 2006 17:25:39 +0100 Subject: [Tioga-users] 3d axes In-Reply-To: <200605310850.37323.roy@mayfield.name> References: <200605310850.37323.roy@mayfield.name> Message-ID: On Wed, 31 May 2006 16:50:37 +0100, Roy Mayfield wrote: > I asked Bill about the same thing last summer, and he gently noted that > that is really easy to do in a ruby script (simpler than his examples). > It took me awhile to get used to the make_preview_pdf() method, but I > now agree with him and suggest that Tioga's code space be guarded for > tough tasks (like your 3D idea, Edwin, which is really cool). It is indeed rather simple and I agree that it should not be included in the FigureMaker class. On the other hand it doesn't make much sense for everyone to write this for himself. That's why it sounds like a good idea to make a separate module that provides some simplification methods around the tough tasks provided by FigureMaker. Stil luckily tioga is written in ruby, so I won't mind having to write/maintain my own helper functions, if people disagree :) Edwin From vincent.fourmond at 9online.fr Wed May 31 09:04:33 2006 From: vincent.fourmond at 9online.fr (vincent.fourmond at 9online.fr) Date: Wed, 31 May 2006 13:04:33 +0000 (GMT) Subject: [Tioga-users] Fwd: Re: 3d axes Message-ID: An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/tioga-users/attachments/20060531/128fed2d/attachment.htm