Message Boards Message Boards

0
|
276247 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

[?] Get dynamic image with different color for each option?

Posted 7 years ago

Consider the following code:

f = {1, x, x^2, x^3}
    Panel[Column[{Row[{CheckboxBar[
          Dynamic[list1], # -> f[[#]] & /@ Range[4]], Dynamic[list1]}], 
       Dynamic[Plot[f[[list1]], {x, 0, 1.5}, 
         PlotStyle -> {Red, Blue, Green, Black}, ImageSize -> 500, 
         AxesStyle -> Thick]]}]]

I want to get a Dynamic image that show differrent functions according to user selection in Checkbox. However, now I get a fine Dynamic image except that all the curves are in the same color. I wanna know How to set the color of each option?

Attachments:
POSTED BY: Wu Falchion

Hello Wu,

Plot has the attribute HoldAll, so you have to make sure that any necessary evaluation inside gets done, using Evaluate[]:

f = {1, x, x^2, x^3}
Panel[Column[{Row[{CheckboxBar[
      Dynamic[list1], # -> f[[#]] & /@ Range[4]], Dynamic[list1]}], 
   Dynamic[Plot[Evaluate@f[[list1]], {x, 0, 1.5}, 
     PlotStyle -> {Red, Blue, Green, Black}, ImageSize -> 500, 
     AxesStyle -> Thick]]}]]

Regards -- Henrik

POSTED BY: Henrik Schachner
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