Message Boards Message Boards

0
|
6658 Views
|
12 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Display 2 datasets in different colors using ListPlot?

Posted 8 years ago

Hi,

I have two large datasets, call them "seq" and "rbspsd". I can plot each alone using ListPlot (i.e., ListPlot[seq] and ListPlot[rbspsd]), but not together, i.e.

ListPlot[{seq, rbspsd}]

I'm not sure what I'm doing wrong. Thanks! -James

p.s. I have a student license, if that matters.

POSTED BY: James Riechel
12 Replies
Anonymous User
Anonymous User
Posted 8 years ago

here are two colors (obviously the list plot flow may not be as intended. you realize ListPlot flows to the right at each datapoint i assume unless x,y is given)

Attachments:
POSTED BY: Anonymous User
Posted 8 years ago

The two colors excite me! What command did you use? I thought I had tried everything this morning. Thanks, -James

POSTED BY: James Riechel

Hi James,

that should basically work out of the box.

list1 = Transpose[{Range[100], RandomReal[1, 100]}];
list2 = Transpose[{Range[100], RandomReal[1, 100]}];
ListPlot[{list1, list2}]

gives

enter image description here

The same thing happens if you use:

list1 = RandomReal[1, 100];
list2 = RandomReal[1, 100];

To see where your problem is it would be useful if you posted running code (in code boxes) and dummy data.

Cheers,

Marco

POSTED BY: Marco Thiel
Posted 8 years ago

Thanks for the post! I solved my problem with:

splot := ListPlot[seq, PlotMarkers -> {Automatic, 10}, PlotStyle -> Opacity[0.5]]
rplot := ListPlot[rbspsd, PlotStyle -> Opacity[0.5, Red], PlotRange -> {0, 1000}, PlotMarkers -> {Automatic, 10}]

(Remember, seq and rbpsd are both in the form {{x1, y1}, {x2, y2}, ...} scatter plot results of experiments.)

And now:

Show[splot, rplot]

I thought I had already tried that this morning, but I must have messed something up.

Thanks everyone for their help and support! James

POSTED BY: James Riechel

It seems that the same PlotRange must be used in the both ListPlot[]:

splot = ListPlot[{{1, 1}, {2, 2}, {3, 3}}, 
  PlotMarkers -> {Automatic, 10}, PlotStyle -> Opacity[0.5], 
  PlotRange -> {{0, 4}, {0, 5}}]
rplot = ListPlot[{{1, 4}, {2, 3}, {3, 2}}, 
  PlotStyle -> Opacity[0.5, Red], PlotMarkers -> {Automatic, 10}, 
  PlotRange -> {{0, 4}, {0, 5}}]

Show[splot, rplot]

enter image description here

Anonymous User
Anonymous User
Posted 8 years ago

you probably are wishing for:

{{1, 2}, {2, 2}, {3, 2}}

ListPlot[{%[[All, 1]], %[[All, 2]]}]

POSTED BY: Anonymous User
Posted 8 years ago

Hmm, I wanted to keep the datasets separate so I can do things such as plot them in different colors, like seq in red and rbspsd in blue.

But thanks for showing me how to merge two data sets.

Sincerely, James

POSTED BY: James Riechel
Anonymous User
Anonymous User
Posted 8 years ago

replacement operator with rules (see: ReplaceAll) is handy to restructure lists:

{{{a},{b}}}/.{{_,_}->Sequence[{a,x},{b,y}]}

{{a,x},{b,y}}

{{a},{b}}//Flatten

{a,b}

one could use Flatten, or Part[], ie b:=a[[1,all,"sam"]], or looping (for i=1...10 do a[[i]]:=b[[j]). but you'll definitely want to restructure List[]s using ReplaceAll not "code programming loops". it will be as or more efficient as well. once in a while you might replace the Head[] of list with Sequence.

POSTED BY: Anonymous User
Posted 8 years ago

Hi! Thanks for the reply!

My data, both seq and rbspsd, are in the following format:

{{x1, y1}, {x2, y2}, ...}

Again, ListPlot[seq] and ListPlot[rbspsd] work great, I just can't get ListPlot[{seq, rbspsd}] to work.

Thanks! James

POSTED BY: James Riechel
Anonymous User
Anonymous User
Posted 8 years ago

the student license does not matter

you may not get some of the prime online content (ready to plot star data, ready to plot geological data), and you cannot use it for work-(job) related uses of any kind (not even so called non-profit gov use). but if you have such need you can upgrade your license at a discount having already bought a lower license - if you do it say in a year or a few.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 8 years ago
ListPlot[{Range[1, 5], Range[5, 10]}]

the structure of the data is important to "easily do it"

on the other hand you might combine plots (there may be a few ways to do so) such as:

ListPlot[Range[1,5]

ListPlot[Range[5,10]

Show[%,%%]

(note if your data is very different the dots may not be all shown unless you limit your plot region to an area where both can be visible within the displayable graphics plot result)

so in summary the structure of your data not in the form {{1,2,3},{4,5,6}}

you might try this and see if the data structure is ok:

ListPlot[{data//Flatten,data2//Flatten}]

if not, then you have {x,y} data or something else. ListPlot handles x,y but again the structure of the list needs to be one of the ones ListPlot is ready to accept. restructure your List[].

POSTED BY: Anonymous User

Hi Johndhend,

the code you post is not properly formatted and incorrect. For example

ListPlot[Range[1,5]

ListPlot[Range[5,10]

is incomplete; the parenthesis do not match up.

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract