From: Luigi B on 16 Sep 2009 05:47 Dear All, I am generating some 2D images with MatrixPlot and using the option PlotRange->{All,All,All}. I know the range that the plotting routine is using for the x- and y- directions. The values of the points (i.e. the z- scale) is changing every image. After plotting, I would like to know what are the values Mathematica has used. Any help? Thanks Luigi
From: Bill Rowe on 17 Sep 2009 06:18 On 9/16/09 at 5:47 AM, l.balzano(a)gmail.com (Luigi B) wrote: >I am generating some 2D images with MatrixPlot and using the option >PlotRange->{All,All,All}. I know the range that the plotting routine >is using for the x- and y- directions. The values of the points >(i.e. the z- scale) is changing every image. After plotting, I would >like to know what are the values Mathematica has used. Any help? Here is an example data = RandomReal[1, {5, 5}]; plot = MatrixPlot[data] In[6]:= PlotRange /. FullOptions[plot] Out[6]= {{0., 5.}, {0., 5.}}
From: Szabolcs Horvát on 18 Sep 2009 05:37 On 2009.09.17. 12:18, Bill Rowe wrote: > On 9/16/09 at 5:47 AM, l.balzano(a)gmail.com (Luigi B) wrote: > >> I am generating some 2D images with MatrixPlot and using the option >> PlotRange->{All,All,All}. I know the range that the plotting routine >> is using for the x- and y- directions. The values of the points >> (i.e. the z- scale) is changing every image. After plotting, I would >> like to know what are the values Mathematica has used. Any help? > > Here is an example > > data = RandomReal[1, {5, 5}]; > plot = MatrixPlot[data] > > In[6]:= PlotRange /. FullOptions[plot] > > Out[6]= {{0., 5.}, {0., 5.}} I would like to draw the attention to the fact that PlotRange (and some other options) are used in two different (but related ways) in Mathematica. This can sometimes be confusing. 1. Every Graphics[] object has an attached coordinate system, and a PlotRange property that controls the region that is shown, in this coordinate system. This is what FullOptions returns when used on a Graphics object. 2. Plotting functions such as LogLogPlot or MatrixPlot have a PlotRange option which specifies which part of the input data will appear in the final plot. The input data often does not map directly to the Graphics coordinates, e.g. in a LogLogPlot, so the PlotRange returned by FullOptions will not be the same that was passed to LogLogPlot. Also, when graphing two-variable functions in 2D (MatrixPlot, DensityPlot, ContourPlot, etc.), PlotRange accepts three bounds: two for the function domain and one for the function value. The OP was asking about the plot range for the function value, which is not preserved in the final Graphics object.
From: Sjoerd C. de Vries on 19 Sep 2009 05:25 Hi Luigi, Since MatrixPlot gets a 2D list as imput that you yourself provide, you already know what values it uses for the z-range, so I assume you want to know what *scaling* Mathematica applied, right? The following does the trick: (* A demo matrix. The fifth power makes for some nice non-uniform distributed data. This is important as we will see later.*) m = RandomReal[{-10, 10}, {20, 20}]^5; (* Use MatrixPlot and Reap/Sow to get the scaled values *) v = Reap[MatrixPlot[m, ColorFunction -> Sow]][[2, 1]]; (* Plot the scaled values against their original input values. See how Mathematica reserves a considerable part of the output range for the part of the input range that contains the most values. Scaling is non-linear!! *) ListPlot[{Flatten[m], v}\[Transpose], PlotRange -> All] Now, I suppose you need these values to draw a legend. To do that, I'm going to borrow David Parks code of April 26th with some changes because of his incorrect assumption that Mathematica's scaling is linear: (* First we need a rescaling function.*) f = Interpolation[{Flatten[m], v}\[Transpose]] (* Now follows David Park's code with changes to accommodate non-linear scaling *) (* If you want to have the default Mathematica colors you'll have to find the default ColorFunction used by MatrixPlot. I couldn't find it in the documentation, so I'll keep David's choice *) matrixplot = MatrixPlot[m, ColorFunction -> "Rainbow"]; legend = DensityPlot[y, {x, 0, 1}, {y, Min[m], Max[m]}, ColorFunction -> (ColorData["Rainbow"][f[#]] &), ColorFunctionScaling -> False, PlotPoints -> 51, AspectRatio -> Full, PlotRange -> {{0, 1}, {Min[m], Max[m]}}, Background -> None, Frame -> True, FrameTicks -> {{None, Range[Round[Min[m]/10000] 10000, 10000 Round[Max[m]/10000], 20000]}, {None, None}}, ImagePadding -> {{2, 50}, {5, 5}}, ImageSize -> {40, 400}]; (* If the range of your actual matrix differs from mine, you'll have to come up with your own FrameTicks code *) Graphics[{Inset[ matrixplot, {4, 4.3}, {Center, Center}, {400, 450} 0.02], Inset[legend, {8.8, 4.2}, {Center, Center}, {7, 40} 0.17], Text[Style["Matrix Plot with Legend", Large], {5, 9.3}], Text[Style["Legend", 14, Bold], {8.5, 8.0}]}, PlotRange -> {{0, 10}, {0, 10}}, Frame -> False, ImageSize -> 600] Hope this helps. Cheers -- Sjoerd
|
Pages: 1 Prev: Problem with NDSolve in Mathematica V4 Next: GUIKit: How to use a widget "Tree"? |