Discussion:
combining ArrayPlot with ListLinePlot
(too old to reply)
Vadim Zaliva
2010-05-19 11:01:43 UTC
Permalink
I have a strange problem with combining 2 plots:

ap = ArrayPlot[Transpose[l]]
lp = ListLinePlot[{a, b, c}]

Each of 'ap' and 'lp' is shown correctly. However combining them via:

Show[ap,lp]

always shows just ap.

Dimensions[Transpose[l]] is {44, 2000}
a,b,c have same dimension {2000}

I feel like I am missing something obvious here...

Vadim
David Park
2010-05-20 00:10:48 UTC
Permalink
What happens if you Show them in the opposite order?


David Park
***@comcast.net
http://home.comcast.net/~djmpark/



From: Vadim Zaliva [mailto:***@gmail.com]

I have a strange problem with combining 2 plots:

ap = ArrayPlot[Transpose[l]]
lp = ListLinePlot[{a, b, c}]

Each of 'ap' and 'lp' is shown correctly. However combining them via:

Show[ap,lp]

always shows just ap.

Dimensions[Transpose[l]] is {44, 2000}
a,b,c have same dimension {2000}

I feel like I am missing something obvious here...

Vadim
David Park
2010-05-20 00:12:14 UTC
Permalink
Actually you did show them in the right order, so we would have to see a
real example.


David Park
***@comcast.net
http://home.comcast.net/~djmpark/




From: Vadim Zaliva [mailto:***@gmail.com]

I have a strange problem with combining 2 plots:

ap = ArrayPlot[Transpose[l]]
lp = ListLinePlot[{a, b, c}]

Each of 'ap' and 'lp' is shown correctly. However combining them via:

Show[ap,lp]

always shows just ap.

Dimensions[Transpose[l]] is {44, 2000}
a,b,c have same dimension {2000}

I feel like I am missing something obvious here...

Vadim
Vadim Zaliva
2010-05-20 00:12:57 UTC
Permalink
Post by David Park
What happens if you Show them in the opposite order?
It still show array plot.
Vivek Joshi
2010-05-20 00:14:01 UTC
Permalink
Post by Vadim Zaliva
ap = ArrayPlot[Transpose[l]]
lp = ListLinePlot[{a, b, c}]
Show[ap,lp]
always shows just ap.
Dimensions[Transpose[l]] is {44, 2000}
a,b,c have same dimension {2000}
This looks fine to me,

l = RandomReal[1, {44, 2000}];

a = ConstantArray[10, {2000}];
b = ConstantArray[20, {2000}];
c = ConstantArray[30, {2000}];

ap = ArrayPlot[l, AspectRatio -> 1];

lp = ListLinePlot[{a, b, c}, PlotStyle -> {Thick}];

Show[ap, lp, FrameTicks -> Automatic]

Vivek
Patrick Scheibe
2010-05-20 00:10:16 UTC
Permalink
Hi,

and setting the DataRange (or searching this forum before asking)
doesn't help?

data = Table[Sin[x*y], {y, -Pi, Pi, 0.1}, {x, -Pi, Pi, 0.1}];
ap = ArrayPlot[data, DataRange -> {{-1, 1}, {-1, 1}}];
lp = ListLinePlot[Transpose[data][[10]], DataRange -> {-1, 1},
PlotStyle -> {{Thick, Red}}];
Show[ap, lp]

Cheers,
Patrick
Post by Vadim Zaliva
ap = ArrayPlot[Transpose[l]]
lp = ListLinePlot[{a, b, c}]
Show[ap,lp]
always shows just ap.
Dimensions[Transpose[l]] is {44, 2000}
a,b,c have same dimension {2000}
I feel like I am missing something obvious here...
Vadim
Vadim Zaliva
2010-05-21 10:47:17 UTC
Permalink
I would like to thank everybody for their answers. The problem is not
solved yet.

I tried setting data range and it did not help. The data used in array
plot has dimensions {44,2000}.

So I expect x to be in range {1,2000} and y in {1,44}.
However when I right click on Array Plot and select "Show
Coordinates" I can see that x is indeed in the right range, but
y range is something like {-45,82}. A screenshot:


http://yfrog.com/afscreenshot20100519at112p

For list line plot, dimensions length all my data vectors is 2000. So
I exect
X range to be {1,2000} and y range depend on data values. Indeed on
the plot
I see ticks showing correct values for X, but "Get Coordinates" shows
x
ranges approx. {-0.1,1}. Screenshot:

http://yfrog.com/eiscreenshot20100519at113p

I think this is the source of the problem. Show using x range
{1,2000}, so all ListLinePlot is probably
squeezed into couple of pixels in the beginning. Result of Show:


http://yfrog.com/1gscreenshot20100519at113p

Show supposed to take range from the first element, but for some
reason changing order of plots in
show does not make any difference.

Sincerely,
Vadim
Vadim Zaliva
2010-05-23 03:33:54 UTC
Permalink
Post by David Park
It might help if you could post the actual, evaluable, Mathematica code, or
maybe the code for a simplified case with simulated data that still exhibits
the same problem.
Just describing what you did in general terms or posting screen shots will
sometimes not capture the source of the problem.
David,

Here is the sample code demonstrating what I am trying to do:

nplevels = RandomReal[{1, 255}, {44, 1000}]
ap = MatrixPlot[nplevels, FrameTicks -> True]
psig = RandomReal[{0, 1}, 1000];
lp = ListLinePlot[{psig}]
Show[ap, lp]

I am trying to combine a matrix representing 2D image with a plot of some signal related to this image. I think the source of my problem is that while X coordinates match, the ranges of Y coordinates very different. It is 1-255 for image data and 0-1 for the signal.

Ideally I would like to have an image plot on top of ListLinePlot. Of course I can combine them via GraphicsColumn, but I want them to be aligned along X coordinates.


Thanks!

Vadim

P.S. I did read and re-read documentation on plot functions an been experimenting with DataRange, PlotRange and other options before seeking kind help from a members of this list :)
David Park
2010-05-23 03:34:05 UTC
Permalink
Vadim,

The following is a method to obtain the ListLinePlot on top of the
MatrixPlot:

nplevels = RandomReal[{1, 255}, {44, 1000}];
psig = RandomReal[{0, 1}, 1000];
lp = ListLinePlot[{psig}];
ap = MatrixPlot[nplevels,
AspectRatio -> 1/GoldenRatio,
FrameTicks -> True,
DataRange -> {{0, 1000}, {0, 1}}];
Show[ap, lp]

You might want different y scales on the left and right sides for the two
sets of data, which you could get by using the FrameTicks option and writing
custom ticks for one side.

The following is a method to obtain the two plots in a column with the x
axes aligned. The trick here is to use the same ImageMargins option in the
two plots such that the left hand tick values for both plots will both fit
in the allotted space.

nplevels = RandomReal[{1, 255}, {44, 1000}];
psig = RandomReal[{0, 1}, 1000];
lp = ListLinePlot[{psig},
Frame -> True,
ImageMargins -> {{20, 10}, {20, 20}}];
ap = MatrixPlot[nplevels,
AspectRatio -> 1/GoldenRatio,
FrameTicks -> {{Automatic, None}, {Automatic, None}},
DataReversed -> False,
DataRange -> {{0, 1000}, All},
ImageMargins -> {{20, 10}, {20, 20}}];
GraphicsColumn[{ap, lp}]


David Park
***@comcast.net
http://home.comcast.net/~djmpark/
Post by David Park
It might help if you could post the actual, evaluable, Mathematica code,
or
Post by David Park
maybe the code for a simplified case with simulated data that still
exhibits
Post by David Park
the same problem.
Just describing what you did in general terms or posting screen shots will
sometimes not capture the source of the problem.
David,

Here is the sample code demonstrating what I am trying to do:

nplevels = RandomReal[{1, 255}, {44, 1000}]
ap = MatrixPlot[nplevels, FrameTicks -> True]
psig = RandomReal[{0, 1}, 1000];
lp = ListLinePlot[{psig}]
Show[ap, lp]

I am trying to combine a matrix representing 2D image with a plot of some
signal related to this image. I think the source of my problem is that while
X coordinates match, the ranges of Y coordinates very different. It is 1-255
for image data and 0-1 for the signal.

Ideally I would like to have an image plot on top of ListLinePlot. Of course
I can combine them via GraphicsColumn, but I want them to be aligned along X
coordinates.


Thanks!

Vadim

P.S. I did read and re-read documentation on plot functions an been
experimenting with DataRange, PlotRange and other options before seeking
kind help from a members of this list :)

Patrick Scheibe
2010-05-22 04:41:10 UTC
Permalink
Hi,
Post by Vadim Zaliva
I would like to thank everybody for their answers. The problem is not
solved yet.
of course this was only a hint which should lead you into the right
direction.
Post by Vadim Zaliva
I tried setting data range and it did not help. The data used in array
plot has dimensions {44,2000}.
So I expect x to be in range {1,2000} and y in {1,44}.
However when I right click on Array Plot and select "Show
Coordinates" I can see that x is indeed in the right range, but
Mathematica makes a lot of stuff to create nice plots. This includes
frames and spaces around plots. So what you see (and get with Show
Coordinates) can be different from the underlying data-range.
But there are options for those settings and a look in the ArrayPlot doc
would have showed you what to try:

nx = 200;
ny = 44;
data1 = Table[
Re[ArcSec[x + I y]], {y, -Pi, Pi, 2 Pi/(ny - 1.)}, {x, -Pi, Pi,
2 Pi/(nx - 1.)}];
ap = ArrayPlot[data, DataRange -> {{0, nx}, {0, ny}},
PlotRangePadding -> None, Frame -> False, ImagePadding -> None,
PlotRangeClipping -> True]

This should give you a graphics where the Show Coordinates should be
what you expected. The data ranges from {{0, 200}, {0, 44}}.

Say, I create now a ListLinePlot with exactly 200 points and the values
range from about 2 to 30.

lp = ListLinePlot[10 data[[22]], PlotRange -> {{0, nx}, Automatic},
DataRange -> {0, nx}]

Combining the two graphics

Show[{ap, lp}]

creates an image where the function-graph goes from the left image
border to the right, as expected. Remembering that the image is 44 units
high, the scale of the y-values in the function seem to fit too.

What I don't understand is, why you care about that "Show Coordinates"
doesn't work as expected. Say I have an ArrayPlot with your data range
and I want to draw a line from the left-lower corner to the right-upper
corner, then the function is 44x/2000:

Show[{ArrayPlot[Table[1, {44}, {2000}],
DataRange -> {{0, 2000}, {0, 44}}],
Plot[44 x/2000., {x, 0, 2000}, PlotStyle -> Yellow]
}]

this is what I wanted. Ok, there is space around the graphics, but the
contents is correct.

Cheers
Patrick
David Park
2010-05-22 04:42:46 UTC
Permalink
It might help if you could post the actual, evaluable, Mathematica code, or
maybe the code for a simplified case with simulated data that still exhibits
the same problem.

Just describing what you did in general terms or posting screen shots will
sometimes not capture the source of the problem.


David Park
***@comcast.net
http://home.comcast.net/~djmpark/



From: Vadim Zaliva [mailto:***@gmail.com]


I would like to thank everybody for their answers. The problem is not
solved yet.

I tried setting data range and it did not help. The data used in array
plot has dimensions {44,2000}.

So I expect x to be in range {1,2000} and y in {1,44}.
However when I right click on Array Plot and select "Show
Coordinates" I can see that x is indeed in the right range, but
y range is something like {-45,82}. A screenshot:


http://yfrog.com/afscreenshot20100519at112p

For list line plot, dimensions length all my data vectors is 2000. So
I exect
X range to be {1,2000} and y range depend on data values. Indeed on
the plot
I see ticks showing correct values for X, but "Get Coordinates" shows
x
ranges approx. {-0.1,1}. Screenshot:

http://yfrog.com/eiscreenshot20100519at113p

I think this is the source of the problem. Show using x range
{1,2000}, so all ListLinePlot is probably
squeezed into couple of pixels in the beginning. Result of Show:


http://yfrog.com/1gscreenshot20100519at113p

Show supposed to take range from the first element, but for some
reason changing order of plots in
show does not make any difference.

Sincerely,
Vadim
Loading...