Skip to main content
Tweeted twitter.com/StackMma/status/1145980564274634752
deleted 2 characters in body
Source Link
chris
  • 23.1k
  • 5
  • 62
  • 151

Context

More often than not I end up doing plots one after the other so that I have a set of plots with the same colour style.

When When I want to make it more publishable ready, I would like to reassign colours to each line.

How to assign colours from a given style to existing sets of plots?

Example

pl1= Plot[Sin[x],{x,0,4Pi}];
pl2= Plot[Cos[2x],{x,0,4Pi}];
Show[pl1,pl2];

Mathematica graphics

Attempt

I while back I wrote the following function

Clear[ShowColor];
ShowColor[list___]:=ShowColor[{list}]/; Length[{list}]>1;
ShowColor[list_,ColorRange->color__,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[color][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]
ShowColor[list_,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[ColorData[10] /@ Range[10]][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]

which uses the GradientColor Package, so that

ShowColor[{pl1,pl2}]

produces

Mathematica graphics

But I am left with the impression that it could be done more elegantly and generally with the modern version of Mathematica, making use of the set of default styles and working in harmony with other features.

Also, my implementation is not very robust. For instance,

 Show[pl1, pl2] // ShowColor 

fails.

What would be great would be to have a function which e.g. would take standard Options such as

 ShowColor[plots,PlotStyle-> ColorData[10]]
 

or

  ShowColor[plots,PlotStyle-> Directive[{Dashed,Blue}]]

Any suggestion on how to make this as generic as possible?

Thanks!

Context

More often than not I end up doing plots one after the other so that I have a set of plots with the same colour style.

When I want to make it more publishable ready, I would like to reassign colours to each line.

How to assign colours from a given style to existing sets of plots?

Example

pl1= Plot[Sin[x],{x,0,4Pi}];
pl2= Plot[Cos[2x],{x,0,4Pi}];
Show[pl1,pl2];

Mathematica graphics

Attempt

I while back I wrote the following function

Clear[ShowColor];
ShowColor[list___]:=ShowColor[{list}]/; Length[{list}]>1;
ShowColor[list_,ColorRange->color__,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[color][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]
ShowColor[list_,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[ColorData[10] /@ Range[10]][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]

which uses the GradientColor Package, so that

ShowColor[{pl1,pl2}]

produces

Mathematica graphics

But I am left with the impression that it could be done more elegantly and generally with the modern version of Mathematica, making use of the set of default styles and working in harmony with other features.

Also, my implementation is not very robust. For instance,

 Show[pl1, pl2] // ShowColor 

fails.

What would be great would be to have a function which e.g. would take standard Options such as

 ShowColor[plots,PlotStyle-> ColorData[10]]
 

or

  ShowColor[plots,PlotStyle-> Directive[{Dashed,Blue}]]

Any suggestion on how to make this as generic as possible?

Thanks!

Context

More often than not I end up doing plots one after the other so that I have a set of plots with the same colour style. When I want to make it more publishable ready, I would like to reassign colours to each line.

How to assign colours from a given style to existing sets of plots?

Example

pl1= Plot[Sin[x],{x,0,4Pi}];
pl2= Plot[Cos[2x],{x,0,4Pi}];
Show[pl1,pl2];

Mathematica graphics

Attempt

I while back I wrote the following function

Clear[ShowColor];
ShowColor[list___]:=ShowColor[{list}]/; Length[{list}]>1;
ShowColor[list_,ColorRange->color__,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[color][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]
ShowColor[list_,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[ColorData[10] /@ Range[10]][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]

which uses the GradientColor Package, so that

ShowColor[{pl1,pl2}]

produces

Mathematica graphics

But I am left with the impression that it could be done more elegantly and generally with the modern version of Mathematica, making use of the set of default styles and working in harmony with other features.

Also, my implementation is not very robust. For instance,

 Show[pl1, pl2] // ShowColor 

fails.

What would be great would be to have a function which e.g. would take standard Options such as

 ShowColor[plots,PlotStyle-> ColorData[10]]
 

or

  ShowColor[plots,PlotStyle-> Directive[{Dashed,Blue}]]

Any suggestion on how to make this as generic as possible?

Thanks!

Became Hot Network Question
added 249 characters in body
Source Link
chris
  • 23.1k
  • 5
  • 62
  • 151

Context

More often than not I end up doing plots one after the other so that I have a set of plots with the same colour style.

When I want to make it more publishable ready, I would like to reassign colours to each line.

How to assign colours from a given style to existing sets of plots?

Example

pl1= Plot[Sin[x],{x,0,4Pi}];
pl2= Plot[Cos[2x],{x,0,4Pi}];
Show[pl1,pl2];

Mathematica graphics

Attempt

I while back I wrote the following function

Clear[ShowColor];
ShowColor[list___]:=ShowColor[{list}]/; Length[{list}]>1;
ShowColor[list_,ColorRange->color__,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[color][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]
     ShowColor[list_,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[ColorData[10] /@ Range[10]][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]

which uses the GradientColor Package, so that

ShowColor[{pl1,pl2}]

produces

Mathematica graphics

But I am left with the impression that it could be done more elegantly and generally with the modern version of Mathematica, making use of the set of default styles and working genericallyin harmony with other features.

MyAlso, my implementation is not very robust. For instance,

 Show[pl1, pl2] // ShowColor 

fails.

What would be great would be to have a function which e.g. would take standard Options such as

 ShowColor[plots,PlotStyle-> ColorData[10]]
 

or

  ShowColor[plots,PlotStyle-> Directive[{Dashed,Blue}]]

Any suggestion on how to make this as generic as possible?

Thanks!

Context

More often than not I end up doing plots one after the other so that I have a set of plots with the same colour style.

When I want to make it more publishable ready, I would like to reassign colours to each line.

How to assign colours from a given style to existing sets of plots?

Example

pl1= Plot[Sin[x],{x,0,4Pi}];
pl2= Plot[Cos[2x],{x,0,4Pi}];
Show[pl1,pl2];

Mathematica graphics

Attempt

I while back I wrote the following function

Clear[ShowColor];
ShowColor[list___]:=ShowColor[{list}]/; Length[{list}]>1;
ShowColor[list_,ColorRange->color__,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[color][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]
     ShowColor[list_,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[ColorData[10] /@ Range[10]][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]

which uses the GradientColor Package, so that

ShowColor[{pl1,pl2}]

produces

Mathematica graphics

But I am left with the impression that it could be done more elegantly and generally with the modern version of Mathematica, making use of the set of default styles and working generically.

My implementation is not very robust. For instance,

 Show[pl1, pl2] // ShowColor 

fails.

Any suggestion on how to make this as generic as possible?

Thanks!

Context

More often than not I end up doing plots one after the other so that I have a set of plots with the same colour style.

When I want to make it more publishable ready, I would like to reassign colours to each line.

How to assign colours from a given style to existing sets of plots?

Example

pl1= Plot[Sin[x],{x,0,4Pi}];
pl2= Plot[Cos[2x],{x,0,4Pi}];
Show[pl1,pl2];

Mathematica graphics

Attempt

I while back I wrote the following function

Clear[ShowColor];
ShowColor[list___]:=ShowColor[{list}]/; Length[{list}]>1;
ShowColor[list_,ColorRange->color__,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[color][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]
ShowColor[list_,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[ColorData[10] /@ Range[10]][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]

which uses the GradientColor Package, so that

ShowColor[{pl1,pl2}]

produces

Mathematica graphics

But I am left with the impression that it could be done more elegantly and generally with the modern version of Mathematica, making use of the set of default styles and working in harmony with other features.

Also, my implementation is not very robust. For instance,

 Show[pl1, pl2] // ShowColor 

fails.

What would be great would be to have a function which e.g. would take standard Options such as

 ShowColor[plots,PlotStyle-> ColorData[10]]
 

or

  ShowColor[plots,PlotStyle-> Directive[{Dashed,Blue}]]

Any suggestion on how to make this as generic as possible?

Thanks!

Source Link
chris
  • 23.1k
  • 5
  • 62
  • 151

Recolour existing plots

Context

More often than not I end up doing plots one after the other so that I have a set of plots with the same colour style.

When I want to make it more publishable ready, I would like to reassign colours to each line.

How to assign colours from a given style to existing sets of plots?

Example

pl1= Plot[Sin[x],{x,0,4Pi}];
pl2= Plot[Cos[2x],{x,0,4Pi}];
Show[pl1,pl2];

Mathematica graphics

Attempt

I while back I wrote the following function

Clear[ShowColor];
ShowColor[list___]:=ShowColor[{list}]/; Length[{list}]>1;
ShowColor[list_,ColorRange->color__,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[color][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]
     ShowColor[list_,opt___]:= Module[{len=Length[list]},
     Table[list[[i]] /. RGBColor[_,_,_]->
          GradientColor[ColorData[10] /@ Range[10]][(i-1)/(len-1)],{i,len}]//Show[#,opt]&]

which uses the GradientColor Package, so that

ShowColor[{pl1,pl2}]

produces

Mathematica graphics

But I am left with the impression that it could be done more elegantly and generally with the modern version of Mathematica, making use of the set of default styles and working generically.

My implementation is not very robust. For instance,

 Show[pl1, pl2] // ShowColor 

fails.

Any suggestion on how to make this as generic as possible?

Thanks!