Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Multiple Line coloring and Dashing in ListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131459] Re: Multiple Line coloring and Dashing in ListPlot
  • From: Nigel King <nigel.king at cambiumnetworks.com>
  • Date: Wed, 10 Jul 2013 03:35:55 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20130703090126.9E0956A93@smc.vnet.net>

All,
I wanted to extend the ideas from Bob and Alexei, because I have had trouble with doing this nicely.

$Version 9.0 for Mac OS X x86 (64-bit) (January 24, 2013)

(* When you want a set of legends one needs to extend the idea a little further *)
(* for a simple table of legends *)
legendTable[pairs_]:=TableForm[pairs,TableSpacing->{1,0.5}]
(* There seems to be no default for dashing so I define noDots *)
noDots=Dashing[{1,0}];
(* Create a general set of PlotStyles for some plots *)
colors={Red,Blue,Green,Brown,Pink,Cyan,Magenta,Gray,Orange};
dashings={noDots,DotDashed,Dotted,Dashed};
plotStyles=Flatten[Table[Directive[i,Thick,j],{j,dashings},{i,colors}]];

(* From an example by Bob Hanlon *)
plotList=Table[{i,RandomReal[{2 i,2 i+1},{20}]},{i,36}];
plots=plotList[[All,2]];
legends=plotList[[All,1]];

ListPlot[plots,
PlotStyle->plotStyles,
Joined->True,
PlotMarkers->Automatic,
ImageSize->600,
AspectRatio->1,
PlotLegends->Placed[LineLegend[plotStyles,legends,
LegendLabel->Style["Plots",16],
LegendFunction->"Frame",LegendMargins->5,LabelStyle->11,
LegendLayout->legendTable],After]]


For the function plots this example may give some useful ideas

(* an interesting example showing a number of techniques which I have learnt *)
(* Create a plot list in an easy to recognise form *)
plotList={
{Sin[x],"sin(x)",{Blue,noDots}},
{Cos[x],"cos(x)",{Red,noDots}},
{Tan[x],"tan(x)",{Green,noDots}},
{Cot[x],"cot(x)",{Brown,Dotted}},
{Sec[x],"sec(x)",{Pink,Dotted}},
{Csc[x],"csc(x)",{Cyan,Dotted}},
{Sinh[x],"sinh(x)",{Blue,DotDashed}},
{Cosh[x],"cosh(x)",{Red,DotDashed}},
{Tanh[x],"tanh(x)",{Green,DotDashed}},
{Coth[x],"coth(x)",{Brown,Dashed}},
{Sech[x],"sech(x)",{Pink,Dashed}},
{Csch[x],"csch(x)",{Cyan,Dashed}}
};

(* extract the plots *)
plots=plotList[[All,1]];
(* extract the legends *)
legends=plotList[[All,2]];
(* extract the plotStyles and control the thickness (in this case Medium is the default)*)
plotStyles=Map[Directive[Thickness[Medium],#[[1]],#[[2]]]&,
plotList[[All,3]]];
(* Modify legendTable to give two columns of functions *)
legendTable[pairs_]:=TableForm[Partition[pairs,6],
TableSpacing->{2,2,0.5},
TableDirections->{Row,Column,Row},
TableAlignments->{Left,Center}]

Plot[plots,{x,0,2Pi},PlotStyle->plotStyles,Frame->True,
PlotLegends->Placed[LineLegend[plotStyles,legends,
LegendLabel->Style["Plots",16],
LegendFunction->"Frame",LegendMargins->5,LabelStyle->11,
LegendLayout->legendTable],After],
ImageSize->500]

I hope this helps

Nigel King



On 3 Jul 2013, at 10:01, graser <graser at gmail.com> wrote:

Dear Mathematica Users,

I have a question about the coloring and dashing lines in listplot.
For example, Let's say there is a multiple data set like
data = Table[RandomReal[{2 i, 2 i + 1}, {20}], {i, 9}];

I want to plot them in listplot or listloglogplot with all different color and all different dashing with (joined -> True).
How can I do it automatically or minimum option?
The default number of coloring in mathematica (I am in still 8) is 4. after that, it repeat same color.

please help me!

Thanks!








  • Prev by Date: numerical integration of vector integrands
  • Next by Date: Re: color surface according to absolut value of the gradient
  • Previous by thread: Re: Multiple Line coloring and Dashing in ListPlot
  • Next by thread: Re: Multiple Line coloring and Dashing in ListPlot