Message Boards Message Boards

1
|
12086 Views
|
7 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How can i change the color of a graphics object?

Posted 9 years ago

I have a number of graphics objects, separately produced. I would like to combine them into one graphic, but color each one differently, so as to distinguish one from another. Something like

Show[
  Style[graph1,Red],
  Style[graph2,Green]
]

but this doesn't work for me. Is there anyway to do this?

Thank you Dave Golber

POSTED BY: David Golber
7 Replies

The PlotStyle option gets hard-wired into the main Graphics data, and Show has no power on it. You may try with a replacement rule like

gr = ListPlot[{1, 2, 3}]
gr[[1]] // InputForm
gr /. RGBColor[___] -> Red
POSTED BY: Gianluca Gorni
Posted 9 years ago

Thank you very much. This works ... basically.

Use // to see what the graphics object really is. In my case, it's got Hue in it. So

Starting with graphics object gr, to set the color to Red, do

grRed = gr/.Hue[ _ , _ , _ ]->H[0,1,1]

POSTED BY: David Golber
Posted 9 years ago

Documentation on Show says "Options explicitly specified in Show override those included in the graphics expression" so I hoped that something like

Show[{p1,p2}, PlotStyle->{Red,Green}]

would work. But it doesn't. I think it would be very useful to be able to combine previously generated graphics in a single plot as you want. Particularly since we would be able to do the basic work without worrying about setting things up for later display. But I don't know how to do this -- maybe others will comment?

POSTED BY: David Keith
Posted 9 years ago

Thanks for trying to help, but this isn't my situation. Let me be more explicit:

gr1=ListPlot@elaborate calculation .... which takes several minutes and I don't want to run it again

gr2=ListPlot@ another elaborate calculation .... which takes several minutes and I don't want to run it again

When I made gr1 and gr2, I didn't plan on showing them together, so I didn't do anything special about the colors. Now I want to put them together, and have gr1 in one color and gr2 in another color. So I want to do something like

Show[ Style[gr1,Red], Style[gr2,Green] ]

but this doesn't work.

POSTED BY: David Golber
Posted 9 years ago

Thanks for trying to help, but this isn't my situation. Let me be more explicit:

gr1=ListPlot@elaborate calculation .... which take several minutes and I don't want to run it again

gr2=ListPlot@ another elaborate calculation .... which take several minutes and I don't want to run it again

When I made gr1 and gr2, I did't plan on showing them together, so I didn't do anything special about the colors. Now I want to put them together, and have gr1 in one color and gr2 in another color. Sop I want to do something like

POSTED BY: David Golber
Posted 9 years ago
Graphics[{{Red, Disk[{0, 0}, 1]}, {Green, Disk[{1, 1}, 1]}}]

enter image description here

POSTED BY: David Keith
Posted 9 years ago

I should also mention that the grouping I used above is not necessary. I often produce that in building the graphic list, but it is only the order that matters.

Graphics[{Blue, Disk[{-1, -1}, 1], Disk[{0, 0}, .5], Yellow, 
  Disk[{1, 1}, 1]}]

enter image description here

POSTED BY: David Keith
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