MathGroup Archive 2007

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

Search the Archive

RE: Non numerical x-axis in (Date)ListPlot?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79011] RE: [mg78986] Non numerical x-axis in (Date)ListPlot?
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Sun, 15 Jul 2007 01:15:44 -0400 (EDT)
  • References: <200707140647.CAA04324@smc.vnet.net>

Hi Maarten,

> I have two sets of data:
> 
> dat1 = {{"A1",2},{"A2",3},{"A4",1}}
> dat2 = {{"A1",2.2},{"A2",2.9},{"A3",0.5},{"A4",1.1}}
> 
> Is there a simple way I can plot these with the {"A1", "A2", 
> "A3", "A4"} as equidistant tick marks/labels along the 
> horizontal axis and a standard numerical vertical axis?
> Note the missing "A3" in dat1.
> 
> I could not find anything in the options of ListPlot, or in 
> the new (6.0) DateListPlot.

There's nothing in your data that look anything like a date, so the absence
of anything in DateListPlot is not surprising.

One way of plotting these data is to set up an indexing scheme corresponding
to your labels and use your labels as tickmarks.

We can make new tick marks using

	lbl = First[#] & /@ dat2;
	tik = {#, lbl[[#]]} & /@ Range[Length@lbl]

So that the first label is "A1" and the last, "A4".

One way of converting your data so thay can be plotted is via the two
functions

	lbl2num[l_] := ToExpression@StringTake[l, -1];
	txt2plt[{x_, y_}] := {lbl2num[x], y}

Which are used as follows

	ListPlot[{txt2plt[#] & /@ dat1, txt2plt[#] & /@ dat2}, FrameTicks ->
{tik, Automatic}, Joined -> True]

There are many other ways of doing this.

Regards,

Dave.


  • Prev by Date: Re: Non numerical x-axis in (Date)ListPlot?
  • Next by Date: Re: Non numerical x-axis in (Date)ListPlot?
  • Previous by thread: Non numerical x-axis in (Date)ListPlot?
  • Next by thread: Re: Non numerical x-axis in (Date)ListPlot?