2
$\begingroup$

I am plotting n spectrum using:

  FileNameSetter[Dynamic[xx]]
  v = Table[Flatten[Import[ xx[[i]] ], 1], {i, 1, Length[xx]}];
  ListLinePlot[Table[v[[jj]], {jj, 1, Length[v]}], 
  PlotRange -> Full, AxesOrigin -> {0, 0}, PlotStyle -> Thick]

where v[[jj]] represens the data that I am plotting.

The problem with that approach is if v[[1, x]] < v[[jj, x]], I cannot view the first spectrum.

Below is part of the result that I got. It has two graphics, but it is almost impossible to see the blue one.

I would like to overlay all the graphics in such a way that I can see all, like showed in this post, but in an easier way, since I cannot understand viewport and all that.

Is there a simpler way to do this?

Edit

Here is an example of data: Spectrum1 Spectrum2

I did some modifications in the code, so now it is more general:

  FileNameSetter[Dynamic[xx]]
  v = Table[Flatten[Import[ xx[[i]] ], 1], {i, 1, Length[xx]}];
  ww = {};
  color = {Blue, Red, Green, Black, White, Gray, Cyan, Magenta, Yellow, Brown, Orange, Pink, Purple};
  With[{opt = 
      Sequence[PlotRange -> {{500, 3000}, {0.9, 10000000}}, 
     ImagePadding -> 35, ImageSize -> 1000,
       BaseStyle -> {18, Bold}]},
    For[jk = 1, jk <= Length[v], jk++,
    If[jk != 1,
      ww = Join[
         ww, {ListLogPlot[v[[jk, 1000 ;;]], PlotStyle -> color[[jk]], Frame -> {{1, 0}, {1, 0}}, Joined -> True, opt]}],
      ww = Join[ww, {ListLogPlot[v[[jk, 1000 ;;]], PlotStyle -> color[[jk]], Frame -> {{1, 0}, {1, 0}}, Joined -> True, opt]}]
       ];
     ];
    Overlay[ww]
    ]

An advantage is that I can overlap 11 graphics together with the same scale (I put the scale but hand, but in principle it is easy to modify that).

I have still two problems:

  1. I can't label the axes;
  2. I can't put a legend without loosing the same scale for all graphics.

Any suggestions?

$\endgroup$
5
  • 1
    $\begingroup$ Hi, set the same ImageSize/AspectRatio, ImagePadding and use Overlay. Please let us know if you get stuck. Also, it is good to include the code you are working on, or at least minimal example of data. $\endgroup$
    – Kuba
    Feb 20, 2014 at 23:46
  • $\begingroup$ Please post your the code you used to produce the image you posted along with the data sets it shows. That will make it easier for people to help you. $\endgroup$
    – m_goldberg
    Feb 21, 2014 at 0:08
  • $\begingroup$ Thanks, @Kuba. Now I updated the code and put an example of data. I tried to use Overlay without success. It does the same as Show. I did not understand why to use ImageSize/AspectRatio, ImagePadding, it did nothing when I tried. Only with Opacity I got some result, but not the best. $\endgroup$
    – Zhozer
    Feb 21, 2014 at 0:24
  • 1
    $\begingroup$ If you set a precise PlotRange (not automatic or all) then there is no need to use Overlay. Try Show then. $\endgroup$
    – Kuba
    Feb 21, 2014 at 23:43
  • $\begingroup$ All mode is not setting all with the same scale. With Show I did not get the same overlay. But at least now it is working, so I just need to improve it. ^^ $\endgroup$
    – Zhozer
    Feb 27, 2014 at 3:13

1 Answer 1

5
$\begingroup$

For the record.

The data you've provided do not match your plot. But here is the way:

dat1 = Import["Spectrum1.dat"]//Flatten;
dat2 = Import["Spectrum2.dat"]//Flatten;

With[{opt = Sequence[PlotRange -> All, ImagePadding -> 35, ImageSize -> 500, 
                     BaseStyle -> {18, Bold}]},
 Overlay[{
          ListLinePlot[dat1, PlotStyle -> Red, FrameStyle -> Red, 
                             Frame -> {{1, 0}, {1, 0}}, opt],
          ListLinePlot[dat2, Frame -> {{0, 1}, {0, 1}}, FrameStyle -> Blue,
                             FrameTicks -> {{None, All}, {None, All}}, opt]
   }]]

enter image description here

Or with PlotRange -> Automatic:

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks @Kuba. I did some modifications, so I can overlap N graphics, N<= 11. But I can't still write a legend automatically (when I do that they loose the common scale), and write a label (I put that information in the opt but it is simply not showing). $\endgroup$
    – Zhozer
    Feb 21, 2014 at 23:10
  • $\begingroup$ @Zhozer hard to guess, maybe ImagePadding is not big enough and label is just outside. Try bigger number. $\endgroup$
    – Kuba
    Feb 21, 2014 at 23:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.