Message Boards Message Boards

0
|
4829 Views
|
7 Replies
|
4 Total Likes
View groups...
Share
Share this post:

PlotStyle don't follows the color range

Posted 3 years ago

Dear All,

PlotStyle doesn't work as it should. The PlotStyle does not follow the "colorRange". There are three different colors (green, blue and red), but they all stay in green?

Please can you help !

Thanks in advance,.... Jos

data = {
   {{2020, 7, 29, 22, 30}, 0}, {{2020, 7, 29, 22, 45}, 
    2}, {{2020, 7, 29, 22, 58}, 3}, {{2020, 7, 29, 23, 0}, 
    2}, {{2020, 7, 29, 23, 8}, 2}, {{2020, 7, 29, 23, 39}, 
    3}, {{2020, 7, 29, 23, 40}, 3}, {{2020, 7, 30, 2, 38}, 
    2}, {{2020, 7, 30, 2, 42}, 2}, {{2020, 7, 30, 2, 47}, 
    2}, {{2020, 7, 30, 2, 48}, 2}, {{2020, 7, 30, 2, 49}, 
    2}, {{2020, 7, 30, 5, 5}, 4}, {{2020, 7, 30, 5, 6}, 
    4}, {{2020, 7, 30, 5, 7}, 3}, {{2020, 7, 30, 5, 51}, 
    2}, {{2020, 7, 30, 5, 52}, 3}, {{2020, 7, 30, 5, 53}, 
    2}, {{2020, 7, 30, 5, 54}, 3}, {{2020, 7, 30, 5, 55}, 
    3}, {{2020, 7, 30, 6, 32}, 2}, {{2020, 7, 30, 6, 33}, 
    3}, {{2020, 7, 30, 6, 34}, 3}, {{2020, 7, 30, 6, 35}, 0}};

colorRange = {
   Green, Blue, Red, Blue, Blue, Blue, Blue, Red, Red, Red, Red, Red, 
   Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, Green};

DateListPlot[data
 , AspectRatio -> 0.8/3, Filling -> Axis, 
 FrameTicks -> {Automatic, {{{{2020, 7, 29, 22, 30}, "\!\(\*
StyleBox[\"22\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"30\",\nFontColor->RGBColor[1, 0, 0]]\)"}, {{2020, 7, 29, 
       23, 00}, "23:00"}, {{2020, 7, 29, 24, 00}, 
      "24:00"}, {{2020, 7, 30, 01, 00}, 
      "01:00"}, {{2020, 7, 30, 02, 00}, 
      "02:00"}, {{2020, 7, 30, 03, 00}, 
      "03:00"}, {{2020, 7, 30, 04, 00}, 
      "04:00"}, {{2020, 7, 30, 05, 00}, 
      "05:00"}, {{2020, 7, 30, 06, 00}, 
      "06:00"}, {{2020, 7, 30, 06, 35}, "\!\(\*
StyleBox[\"06\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"35\",\nFontColor->RGBColor[1, 0, 0]]\)"}}, None}}, 
 ImageSize -> 600, Joined -> False, 
 LabelStyle -> Directive[Black, Bold, 10]
 , PlotStyle -> colorRange
 ]

enter image description here

POSTED BY: Jos Klaps
7 Replies

Look what happens here

DateListPlot[List /@ data, PlotStyle -> colorRange]
POSTED BY: Hans Dolhaine

Sort of a workaround:

data = {{{2020, 7, 29, 22, 30}, 0}, {{2020, 7, 29, 22, 45}, 
    2}, {{2020, 7, 29, 22, 58}, 3}, {{2020, 7, 29, 23, 0}, 
    2}, {{2020, 7, 29, 23, 8}, 2}, {{2020, 7, 29, 23, 39}, 
    3}, {{2020, 7, 29, 23, 40}, 3}, {{2020, 7, 30, 2, 38}, 
    2}, {{2020, 7, 30, 2, 42}, 2}, {{2020, 7, 30, 2, 47}, 
    2}, {{2020, 7, 30, 2, 48}, 2}, {{2020, 7, 30, 2, 49}, 
    2}, {{2020, 7, 30, 5, 5}, 4}, {{2020, 7, 30, 5, 6}, 
    4}, {{2020, 7, 30, 5, 7}, 3}, {{2020, 7, 30, 5, 51}, 
    2}, {{2020, 7, 30, 5, 52}, 3}, {{2020, 7, 30, 5, 53}, 
    2}, {{2020, 7, 30, 5, 54}, 3}, {{2020, 7, 30, 5, 55}, 
    3}, {{2020, 7, 30, 6, 32}, 2}, {{2020, 7, 30, 6, 33}, 
    3}, {{2020, 7, 30, 6, 34}, 3}, {{2020, 7, 30, 6, 35}, 0}};
colorRange = {Green, Blue, Red, Blue, Blue, Blue, Blue, Red, Red, Red,
    Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, 
   Green};
pos = Map[Flatten, 
   Position[colorRange, #] & /@ {Green, Blue, Red}, {1}];


ptgrn = data[[#]] & /@ pos[[1]];
ptblu = data[[#]] & /@ pos[[2]];
ptred = data[[#]] & /@ pos[[3]];
DateListPlot[{ptgrn, ptblu, ptred}, AspectRatio -> 0.8/3, 
 Filling -> Axis, 
 FrameTicks -> {Automatic, {{{{2020, 7, 29, 22, 30}, "\!\(\*
      StyleBox[\"22\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
      StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
      StyleBox[\"30\",\nFontColor->RGBColor[1, 0, 0]]\)"}, {{2020, 7, 
       29, 23, 00}, "23:00"}, {{2020, 7, 29, 24, 00}, 
      "24:00"}, {{2020, 7, 30, 01, 00}, 
      "01:00"}, {{2020, 7, 30, 02, 00}, 
      "02:00"}, {{2020, 7, 30, 03, 00}, 
      "03:00"}, {{2020, 7, 30, 04, 00}, 
      "04:00"}, {{2020, 7, 30, 05, 00}, 
      "05:00"}, {{2020, 7, 30, 06, 00}, 
      "06:00"}, {{2020, 7, 30, 06, 35}, "\!\(\*
      StyleBox[\"06\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
      StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
      StyleBox[\"35\",\nFontColor->RGBColor[1, 0, 0]]\)"}}, None}}, 
 ImageSize -> 600, Joined -> False, 
 LabelStyle -> Directive[Black, Bold, 10], 
 PlotStyle -> {{PointSize[.02], Green}, {PointSize[.015], 
    Blue}, {PointSize[.0095], Red}}]
POSTED BY: Hans Dolhaine

Your variable data contains only one dataset, so WL reads only the first directive in Plotstyle. For the color specifications that you need it is enough to wrap you variable data as follows DateListPlot[ Partition[data, 1], ...]

data = {
   {{2020, 7, 29, 22, 30}, 0}, {{2020, 7, 29, 22, 45}, 
    2}, {{2020, 7, 29, 22, 58}, 3}, {{2020, 7, 29, 23, 0}, 
    2}, {{2020, 7, 29, 23, 8}, 2}, {{2020, 7, 29, 23, 39}, 
    3}, {{2020, 7, 29, 23, 40}, 3}, {{2020, 7, 30, 2, 38}, 
    2}, {{2020, 7, 30, 2, 42}, 2}, {{2020, 7, 30, 2, 47}, 
    2}, {{2020, 7, 30, 2, 48}, 2}, {{2020, 7, 30, 2, 49}, 
    2}, {{2020, 7, 30, 5, 5}, 4}, {{2020, 7, 30, 5, 6}, 
    4}, {{2020, 7, 30, 5, 7}, 3}, {{2020, 7, 30, 5, 51}, 
    2}, {{2020, 7, 30, 5, 52}, 3}, {{2020, 7, 30, 5, 53}, 
    2}, {{2020, 7, 30, 5, 54}, 3}, {{2020, 7, 30, 5, 55}, 
    3}, {{2020, 7, 30, 6, 32}, 2}, {{2020, 7, 30, 6, 33}, 
    3}, {{2020, 7, 30, 6, 34}, 3}, {{2020, 7, 30, 6, 35}, 0}};

colorRange = {
   Green, Blue, Red, Blue, Blue, Blue, Blue, Red, Red, Red, Red, Red, 
   Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, Red, Green};

DateListPlot[Partition[data, 1]
 , AspectRatio -> 0.8/3, Filling -> Axis, 
 FrameTicks -> {Automatic, {{{{2020, 7, 29, 22, 30}, "\!\(\*
StyleBox[\"22\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"30\",\nFontColor->RGBColor[1, 0, 0]]\)"}, {{2020, 7, 29, 
       23, 00}, "23:00"}, {{2020, 7, 29, 24, 00}, 
      "24:00"}, {{2020, 7, 30, 01, 00}, 
      "01:00"}, {{2020, 7, 30, 02, 00}, 
      "02:00"}, {{2020, 7, 30, 03, 00}, 
      "03:00"}, {{2020, 7, 30, 04, 00}, 
      "04:00"}, {{2020, 7, 30, 05, 00}, 
      "05:00"}, {{2020, 7, 30, 06, 00}, 
      "06:00"}, {{2020, 7, 30, 06, 35}, "\!\(\*
StyleBox[\"06\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\":\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"35\",\nFontColor->RGBColor[1, 0, 0]]\)"}}, None}}, 
 ImageSize -> 600, Joined -> False, 
 LabelStyle -> Directive[Black, Bold, 10]
 , PlotStyle -> colorRange
 ]

enter image description here

POSTED BY: Diego Ramos

But why does

PlotStyle -> {PointSize[.008], #} & /@ colorRange

not work?

POSTED BY: Hans Dolhaine

Dear Hans and Diego,

Thanks for your information and help. Your proposals are brilliant.

Note: My goal is to create a graph showing the severity of subjective brain spikes during the night (ratings scale 0...4).

Best Regards and thanks again for your help,.... Jos

@Hans, Viele Grusse und danke schon fur Ihre Hilfe,

@Diego, Muchos saludos y gracias por su ayuda.

POSTED BY: Jos Klaps

In order to fix the scope of the use of Map you can use parenthesis as follows PlotStyle -> ({PointSize[0.008], #}& /@ colorRange)

POSTED BY: Diego Ramos

Gracias. That's it. Very interesting.

POSTED BY: Hans Dolhaine
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