Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Kuba, PlatoManiac, Michael E2, rm -rf Feb 21 at 2:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
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. –  Kuba Feb 20 at 23:46
    
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. –  m_goldberg Feb 21 at 0:08
    
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. –  Zhozer Feb 21 at 0:24
1  
If you set a precise PlotRange (not automatic or all) then there is no need to use Overlay. Try Show then. –  Kuba Feb 21 at 23:43
    
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. ^^ –  Zhozer Feb 27 at 3:13

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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). –  Zhozer Feb 21 at 23:10
    
@Zhozer hard to guess, maybe ImagePadding is not big enough and label is just outside. Try bigger number. –  Kuba Feb 21 at 23:44

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