# 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?

edit retag close merge delete

Sort by ยป oldest newest most voted

Asking for the doc via ?density_plot in the sage console gives a lot of information:

Signature:      density_plot(*args, **kwds)
Docstring:
"density_plot" takes a function of two variables, f(x,y) and plots
the height of the function over the specified "xrange" and "yrange"
as demonstrated below.

"density_plot(f, (xmin,xmax), (ymin,ymax), ...)"

INPUT:

* "f" -- a function of two variables

* "(xmin,xmax)" -- 2-tuple, the range of "x" values OR 3-tuple
"(x,xmin,xmax)"

* "(ymin,ymax)" -- 2-tuple, the range of "y" values OR 3-tuple
"(y,ymin,ymax)"

The following inputs must all be passed in as named parameters:

* "plot_points" -- integer (default: 25); number of points to
plot in each direction of the grid

* "cmap" -- a colormap (default: "'gray'"), the name of a
predefined colormap, a list of colors or an instance of a
matplotlib Colormap. Type: "import matplotlib.cm;

* "interpolation" -- string (default: "'catrom'"), the
interpolation method to use: "'bilinear'", "'bicubic'",
"'bessel'", "'mitchell'", "'lanczos'", "'catrom'", "'hermite'",
"'hanning'", "'hamming'", "'kaiser'"

EXAMPLES:


and so on. (Truncated.) The many doc examples are not related to the option specifying the color map...

The one subquestion about the function (being a synonym to curve, or not), is immediately cleared, density plots are done for functions from a domain inside $\mathbb R^2$ with values in $\mathbb R$. The "height" of a function is then "giving the color".

(So the graph is not a curve in plane, but a "hill in 3D", the height is picking "the right color" from the color chosen scheme.)

The colors now.

From the sage interpreter console, the default seems to be "gray". The question mentions red + blue, so i have to guess that some other interface is using these colors by default. Possible color schemes are in the list:

sage: import matplotlib.cm
sage: cmapList . sort()
sage: cmapList[:10]
[u'Accent',
u'Accent_r',
u'Blues',
u'Blues_r',
u'BrBG',
u'BrBG_r',
u'BuGn',
u'BuGn_r',
u'BuPu',
u'BuPu_r']


(Only the first ten shown.)

Starting from the code:

var( 'x,y' );
def f(x,y):    return exp( -x^2-y^2 )


one can thus try the color maps / schemes:

density_plot( f, (x,-1,1), (y,-1,1) )    # gray
density_plot( f, (x,-1,1), (y,-1,1), cmap='Accent' )
density_plot( f, (x,-1,1), (y,-1,1), cmap='Spectral' )
density_plot( f, (x,-1,1), (y,-1,1), cmap='Blues' )
density_plot( f, (x,-1,1), (y,-1,1), cmap='brg' )
density_plot( f, (x,-1,1), (y,-1,1), cmap='brg_r' )    # brg reversed
density_plot( f, (x,-1,1), (y,-1,1), cmap='gnuplot' )


and so on.

more

@Dan By height I assume the y-value which is real. but what is meant by "from a domain inside R2 with values in R" . For height we already have the usual plot? I don't understand it.

( 2017-06-13 13:34:31 +0200 )edit

If it is $\mathbb R^2$then it's a complex value not a real one?

( 2017-06-13 13:37:36 +0200 )edit

@dan_fulea maybe, I mean how is the density calculated? If I can understand that, it might help to understand what is the meaning of density of sin(x)?

( 2017-06-13 13:52:59 +0200 )edit

@Dan another question is how is it a 3d graph, in wikipedia and else where they all just draw a 2d graph? From where did the extra information for the 3rd axis take over?

( 2017-06-13 14:11:29 +0200 )edit

Sorry, missed the comments till today. I'll try to answer to all questions at once. Let us run the following code in sage:

sage: var( 'x,y' );
sage: def f(x,y):    return exp( -x^2-y^2 )
sage: plot3d( f, (x,-1,1), (y,-1,1) )
Launched jmol viewer for Graphics3d Object


Then jmol starts a plot, over a plain square there is a small surface hanging in the air. The square is implicitly drawn for the axes $Ox$, and $x$ is running from $-1$ to $1$, and $Oy$, and $y$ also runs from $-1$ to $1$. The "hill over the square" is a 3d object. Now let us use a source of light exactly over the top of the hill. (Best, one with homogenous parallel vertical rays.) Because of the blur, the top of the hill is white, and the valley is dark. This corresponds to a black ...(more)

( 2017-06-29 04:37:52 +0200 )edit