Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

Define a density plot?

asked 7 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 7 years ago

dan_fulea gravatar image

updated 7 years ago

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;
     matplotlib.cm.datad.keys()" 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'"

   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 R2 with values in 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 = matplotlib.cm.datad.keys()
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.

Preview: (hide)
link

Comments

@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 ( 7 years ago )

If it is R2then it's a complex value not a real one?

screened00 gravatar imagescreened00 ( 7 years ago )

@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 ( 7 years ago )

@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 ( 7 years ago )

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 ( 7 years ago )

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

Stats

Asked: 7 years ago

Seen: 882 times

Last updated: Jun 09 '17