ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 08 Jun 2017 22:09:45 +0200Define a density plot?https://ask.sagemath.org/question/37874/define-a-density-plot/I was wondering, since a function is a curve, it does not have a density unlike prime density,signal density,etc?
And does it plot on `complex or real numbers`?
What is the meaning of all the colors from red to blue? screened00Thu, 08 Jun 2017 22:09:45 +0200https://ask.sagemath.org/question/37874/I want my plotting function to treat numbers as numbers, not variableshttps://ask.sagemath.org/question/35246/i-want-my-plotting-function-to-treat-numbers-as-numbers-not-variables/ I'm creating a plot, like this:
density_plot(f(x, y), (x, 0, 1), (y, 0, 1))
The function *f* looks basically like this:
def f(x, y):
u = vector([x, y, 1 - x - y])
return u.norm(2)
That works. Now I introduce a vector v like this:
def f(x, y):
u = vector([x, y, 1 - x - y])
v = vector([5, 4, 2])
return (u - v).norm(2)
That works. But if v is the solution of an equation, like this:
v = M.right_kernel().basis()[0]
Now Sage can't handle the subtraction u - v:
> TypeError: unsupported operand parent(s) for '-': 'Vector space of dimension 3 over Symbolic Ring' and 'Vector space of degree 3 and dimension 1 over Real Field with 53 bits of precision Basis matrix:[ 1.00000000000000 0.571428571428571 1.57142857142857]'
So okay, I get that basically what's happening is that u consists of symbolic polynomials in x and y, but v consists of actual numbers, or something like that. But why is it not a problem when v is defined explicitly by `vector([5, 5, 5])` or whatever? What is it about the object returned by `.right_kernel().basis()[0]` (which in all other respects behaves like a vector) that's so incompatible in this context?
How can I solve the matrix equation Mx = 0 in such a way that the vector I get can be subtracted from u? Note that M is singular in my case, with nullity 1, so I need to be able to get an arbitrary vector out of its nullspace.JackMMon, 24 Oct 2016 17:30:39 +0200https://ask.sagemath.org/question/35246/List Density Plot?https://ask.sagemath.org/question/26121/list-density-plot/How can I make a 2-D density plot of a list of values in Sage?
I'd like to make something like this:
![Density map](http://pelican.rsvs.ulaval.ca/mediawiki/images/c/cf/Density_map.png)
([image source](http://pelican.rsvs.ulaval.ca/mediawiki/index.php/Making_density_maps_using_Gnuplot#Introduction))GeremiaTue, 10 Mar 2015 00:36:55 +0100https://ask.sagemath.org/question/26121/density_plot + def'ed python function = TypeError?https://ask.sagemath.org/question/25617/density_plot-defed-python-function-typeerror/I have the following functions:
var('a, b')
# This will work with both contour_plot and density_plot
f1(a, b) = 1 - b / a
# So will this
f2(a, b) = 1 - a / b
# This only works with contour_plot?!
def f12(a, b):
if a - b < 0:
return f1(a, b)
else:
return f2(a, b)
Obviously, `f1` and `f2` are symbolic functions, where `f12` is a `def`'ed python function. Calling `contour_plot` works on all three. Calling `density_plot` works on `f1` and `f2`, but raises a `TypeError` when called with `f12`, the `def`'ed python function.
I've [created a project](https://cloud.sagemath.com/projects/443a2a33-d145-4b63-893f-175543cc50c6/files/Test%20Case.sagews) that has an interactive session demonstrating the problem.
Here's the trace:
Error in lines 1-1
Traceback (most recent call last):
...
File "/projects/443a2a33-d145-4b63-893f-175543cc50c6/.sagemathcloud/sage_salvus.py", line 2306, in show
show_2d_plot_using_matplotlib(obj, svg=svg, **kwds)
File "/projects/443a2a33-d145-4b63-893f-175543cc50c6/.sagemathcloud/sage_salvus.py", line 2229, in show_2d_plot_using_matplotlib
obj.save(t, **kwds)
File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 471, in wrapper
return func(*args, **kwds)
File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/plot/graphics.py", line 2972, in save
figure = self.matplotlib(**options)
File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/plot/graphics.py", line 2418, in matplotlib
g._render_on_subplot(subplot)
File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/plot/density_plot.py", line 146, in _render_on_subplot
subplot.imshow(self.xy_data_array, origin='lower', cmap=cmap, extent=(x0,x1,y0,y1), interpolation=options['interpolation'])
File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axes.py", line 7300, in imshow
im.set_data(X)
File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/image.py", line 425, in set_data
raise TypeError("Image data can not convert to float")
TypeError: Image data can not convert to float
Am I asking `density_plot` to do something crazy here? If not, what am I doing wrong?positaTue, 27 Jan 2015 20:32:24 +0100https://ask.sagemath.org/question/25617/Density plot aspect ratiohttps://ask.sagemath.org/question/10642/density-plot-aspect-ratio/I am trying to make a very high aspect ratio density plot, but I can't seem to manually adjust the aspect ratio, and the automatically generated plot ends up being just a very pretty line. What am I doing wrong? The code I'm using is below. I don't know how to use Markdown to make it look pretty, sorry :(
print("Diffusion length data")
k = 1.381E-023
T = 300
q = 1.602E-019
var('ue')
De(ue) = ue*k*T/q
var('tau')
Le = (tau*10^-9*De)^(1/2)
D = density_plot(Le*10^4, (tau, 0, 3), (ue, 0, 500), cmap="jet")
D.show(aspect_ratio=0.05)wlp2Mon, 21 Oct 2013 15:23:45 +0200https://ask.sagemath.org/question/10642/Colorbar for density plotshttps://ask.sagemath.org/question/9460/colorbar-for-density-plots/Hi!
I would like to know if there is a way to get a colorbar for a density plot. For contour plots this works fine with the colorbar=True option, but for density plots there doesn't seem to be such an option. Can anyone help?
Greetings,
MelvinMelvinSmithTue, 23 Oct 2012 20:57:25 +0200https://ask.sagemath.org/question/9460/Overlaying plots in a specific orderhttps://ask.sagemath.org/question/8510/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)? JasonThu, 24 Nov 2011 18:51:40 +0100https://ask.sagemath.org/question/8510/