2022-06-22 11:10:58 +0100 received badge ● Famous Question (source) 2016-12-30 16:41:26 +0100 received badge ● Notable Question (source) 2016-12-30 16:41:26 +0100 received badge ● Popular Question (source) 2015-07-22 06:09:08 +0100 received badge ● Famous Question (source) 2014-08-01 10:23:08 +0100 received badge ● Famous Question (source) 2014-06-29 03:15:04 +0100 marked best answer Overlaying plots in a specific order I've got two plots: one is a density plot, one is a list plot. I'd like to combine the plots in such a way that the list plot is overlaid on top of the density plot, so the dots or visible. No matter what I do, it seems that the density plot is always in front and list plot is in back. This isn't my code, but it appears to have the same behavior: sage: x_coords = [cos(t)^3 for t in srange(0, 2*pi, 0.02)] sage: y_coords = [sin(t)^3 for t in srange(0, 2*pi, 0.02)] sage: h1 = list_plot(zip(x_coords, y_coords)) sage: x,y = var('x,y') sage: h2 = density_plot(sin(x)*sin(y), (x, -2, 2), (y, -2, 2), cmap='jet') sage: h1+h2  How can I make the list plot on top (or in general, specify the order of any combined plots)? 2014-06-29 03:14:59 +0100 marked best answer Plot doesn't seem to evaluate my function I've got a custom function I wrote and I'm trying to plot it. Actually, I'm trying to do an xy density plot but the density plot function was flat (all blue). So I'm trying to plot in a single variable to see what's going on, and the result is all zeroes. However, when I evaluate my function at several points, none of them are zero. Here's some code showing my function being evaluated at several points vs what plot gives me. Any idea what's going on? tags = [] for i in range(12): for j in range(12): tags.append((i*8, j*8, 3)) def getdist((x0,y0,z0),(x1,y1,z1)): return sqrt((x1-x0)^2+(y1-y0)^2+(z1-z0)^2.) def sum_of_distances((x,y,z), tags, maxdist): cumdist = 0 for tag in tags: dist = getdist((x,y,z), tag) if dist <= maxdist: cumdist = cumdist + dist return cumdist #this shows we have real numbers for i in range(10): print sum_of_distances((i,1,1), tags, 30) #this just shows a y value of 0 (x is 0 to 10) plot(sum_of_distances((x,1,1), tags, 30),(x,0,10))  2013-11-15 05:10:48 +0100 received badge ● Famous Question (source) 2013-11-03 08:54:40 +0100 received badge ● Nice Answer (source) 2013-10-10 02:35:52 +0100 received badge ● Notable Question (source) 2013-07-27 14:54:14 +0100 received badge ● Nice Question (source) 2013-06-09 07:09:43 +0100 received badge ● Taxonomist 2013-04-24 05:54:06 +0100 received badge ● Notable Question (source) 2013-02-28 14:05:56 +0100 received badge ● Notable Question (source) 2013-02-18 09:41:35 +0100 received badge ● Necromancer (source) 2013-02-18 09:41:35 +0100 received badge ● Teacher (source) 2012-12-27 18:16:55 +0100 received badge ● Popular Question (source) 2012-11-23 05:40:37 +0100 received badge ● Popular Question (source) 2012-11-06 16:50:22 +0100 received badge ● Popular Question (source) 2012-01-16 15:56:17 +0100 answered a question suppressing output in notebook Another thing you can do is just put the keyword "None" as the last line in the cell. Example: 1+1 None  2011-12-01 18:13:30 +0100 commented answer Is there a simple way to plot an image in a notebook? I.e. the output of the imshow function in matplotlib... Do these saved files ever get deleted once they are created? 2011-12-01 18:13:30 +0100 received badge ● Commentator 2011-12-01 16:29:33 +0100 answered a question Is there a simple way to plot an image in a notebook? I.e. the output of the imshow function in matplotlib... Do these saved files ever get deleted once they are created? 2011-12-01 16:16:40 +0100 commented answer log base 10 If you could make this change it would be great: "EXAMPLES: sage: log(e^2)" : To something like: EXAMPLES: To change the base of the logarithm, add a second parameter. sage: log(1000,10): 3 Small change but helpful! 2011-12-01 13:24:15 +0100 marked best answer log base 10 This is in log?:  EXAMPLES: sage: log(e^2) 2 sage: log(1024, 2); RDF(log(1024, 2)) 10 10.0  So log(x,10) should be what you're looking for... 2011-12-01 13:23:51 +0100 commented answer log base 10 Thanks, I wasn't aware that log_b(x) was equivalent to log(x)/log(b). Might be good to add that to the docs. (I got hung up because I saw log(10)/log(2) in the log? documentation and assumed it meant that log(x,y) was something that didn't help me, because it didn't say "To use the log in base b, do this") 2011-12-01 12:46:54 +0100 asked a question log base 10 Is there a built-in way to use a log with base other than e? The log documentation doesn't show any example (I thought log(10,x) was what I wanted for a while but it's actually different than what one might expect). 2011-11-30 21:47:36 +0100 commented question Public interactive not working Good question, this would also be a highly useful feature for me as well. 2011-11-30 16:21:24 +0100 commented answer Plot doesn't seem to evaluate my function Wouldn't it be possible to have an overloaded plot function that behaved differently depending on the input type? When it received a sage class input type it would behave one way, when it received a function input type it would behave another way. 2011-11-28 16:03:40 +0100 received badge ● Student (source) 2011-11-25 21:12:58 +0100 marked best answer Overlaying plots in a specific order You might be interested in the answers to this question about zordering.. You can choose how to zorder (i.e. choose the "depth" of an image) by calling set_zorder on the resulting graphics objects [not on the plots]. For example: sage: x_coords = [cos(t)^3 for t in srange(0, 2*pi, 0.02)] sage: y_coords = [sin(t)^3 for t in srange(0, 2*pi, 0.02)] sage: h1 = list_plot(zip(x_coords, y_coords)) sage: x,y = var('x,y') sage: h2 = density_plot(sin(x)*sin(y), (x, -2, 2), (y, -2, 2), cmap='jet') sage: h = h1+h2 sage: list(h) [Point set defined by 315 point(s), DensityPlot defined by a 25 x 25 data grid] sage: h[0].set_zorder(10) sage: show(h)  But I have to admit that it doesn't look like all the objects you might want to support zordering the way they should: sage: h[1].set_zorder(20) sage: show(h) verbose 0 (138: primitive.py, options) WARNING: Ignoring option 'zorder'=20 verbose 0 (138: primitive.py, options) The allowed options for DensityPlot defined by a 25 x 25 data grid are: cmap the name of a predefined colormap, a list of colors or an instance of a matplotlib Colormap. Type: import matplotlib.cm; matplotlib.cm.datad.keys() for available colormap names. interpolation What interpolation method to use plot_points How many points to use for plotting precision  This is an inconvenience because it's not pretty to force it via the underlying matplotlib objects, but I might be missing something. 2011-11-25 01:15:19 +0100 marked best answer Plot doesn't seem to evaluate my function The problem is how binding works in Python. sum_of_distances is a Python function, so it's evaluated immediately. So your plot command is really equivalent to onepoint = sum_of_distances((x,1,1), tags, 30) plot(onepoint, (x, 0, 10))  And it so happens that: sage: sum_of_distances((x,1,1), tags, 30) 0  because this requires testing whether (e.g.) sqrt(x^2+9) < 30, which returns false because Sage doesn't know how to prove it's true (and it's not in general, as x is a symbolic variable which could be anything), so cumdist stays at 0. One way to get what you want is to use a lambda function to delay evaluation: plot(lambda x: sum_of_distances((x,1,1), tags, 30),(0,10))  (BTW, you might be interested in CartesianProduct and in generator expressions-- they can simplify some code like this.)