Ask Your Question

Define a density plot?

asked 2017-06-08 22:09:45 +0200

screened00 gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-06-08 23:59:19 +0200

dan_fulea gravatar image

updated 2017-06-09 00:02:22 +0200

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

Signature:      density_plot(*args, **kwds)
   "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), ...)"


   * "f" -- a function of two variables

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

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

   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;" for available colormap names.

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


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
sage: cmapList =
sage: cmapList . sort()
sage: cmapList[:10]

(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.

edit flag offensive delete link 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.

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

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

screened00 gravatar imagescreened00 ( 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)?

screened00 gravatar imagescreened00 ( 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?

screened00 gravatar imagescreened00 ( 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)

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-06-08 22:09:45 +0200

Seen: 591 times

Last updated: Jun 09 '17