Ask Your Question

Define a density plot?

asked 2017-06-08 15:09:45 -0500

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 16:59:19 -0500

dan_fulea gravatar image

updated 2017-06-08 17:02:22 -0500

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 06:34:31 -0500 )edit

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

screened00 gravatar imagescreened00 ( 2017-06-13 06:37:36 -0500 )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 06:52:59 -0500 )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 07:11:29 -0500 )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-28 21:37:52 -0500 )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 15:09:45 -0500

Seen: 40 times

Last updated: Jun 08