Re: Controling the color of line segments in a Log plot
- To: mathgroup at smc.vnet.net
- Subject: [mg90157] Re: Controling the color of line segments in a Log plot
- From: "David Park" <djmpark at comcast.net>
- Date: Tue, 1 Jul 2008 06:57:53 -0400 (EDT)
- References: <g4a6r8$8s5$1@smc.vnet.net>
Using your sample point list: yValues = Table[10^n, {n, 10}] xy = Transpose[{Range[Length[yValues]], yValues}] One might have hoped that the following construction would work: ListLogPlot[xy, Joined -> True, ColorFunction -> Function[{x, y}, If[3 <= x <= 6, Red, Black]]] But it doesn't. Perhaps someone will know how to make that approach work. So I go to a more detailed approach using the Presentations package. This parallels your second approach but without all the level jumping. First, we need a format function for the y tick labels. Needs["Presentations`Master`"] nformat[n_] := Switch[n, 1, 1, 10, 10, _, Superscript[10, Log[10, n]]] Then we construct custom ticks and grids. I'm going to use a Frame plot with a light grid. yticks = CustomTicks[Log, {1, 10, {1}, {2, 3, 4, 5, 6, 7, 8, 9}}, CTNumberFunction -> (nformat[#] &)]; ygrid = CustomGridLines[Log, {1, 10, Range[9]}, {LightGray}]; xgrid = CustomGridLines[Identity, {1, 10, 1}, {LightGray}]; Then we can draw the custom plot, using separate draw statements for the regions of the curve: Draw2D[ {ListLogDraw[Take[xy, {1, 3}], Joined -> True], ListLogDraw[Take[xy, {6, 10}], Joined -> True], Red, ListLogDraw[Take[xy, {3, 6}], Joined -> True]}, AspectRatio -> 1, PlotRange -> {{1, 10}, {Log[10], Log[10^10]}}, Frame -> True, FrameTicks -> {{yticks, yticks // NoTickLabels}, {Automatic, Automatic}}, GridLines -> {xgrid, ygrid}, ImageSize -> 500] I could have used PlotRange -> {{1, 10}, All} but I gave explicit values to the y plot range just to show that, in fact, Mathematica DOES use the natural log for the underlying plot values. Also notice that I used natural log in the CustomTicks and CustomGrid functions as the routine to get from the label value to the underlying plot value. -- David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ "Donald DuBois" <donabc at comcast.net> wrote in message news:g4a6r8$8s5$1 at smc.vnet.net... >I would like to control the color of line segments in a Log plot. I have >three Questions (A,B,C) regarding this problem. > > A simple example: I start with the data yValues = Table[10^n, {n,10}] - > which should also be the Y-axis tick values - and use ListLogPlot to graph > it. > > yValues = Table[10^n, {n, 10}] > xy = Transpose[{Range[Length[yValues]], yValues}] > ListLogPlot[xy, Joined -> True] > > > Question A . Does anyone find it peculiar that ListLogPlot seems to be > taking > Log to base 10 as a default as in the above plot when Log by itself > defaults to base E? This is FINE for me, as I want it to be to the base > 10. But still, > does anyone know why this is so or am I misconstruing something? > > > Question B. > I would like to change the color to Red of the line segment with X values > going from > 3 to 6. (In general, I would like to change the segment color to Red for > any number of segments of the same Log plot.) Is there a way to do this at > the ListLogPlot level (i.e.giving directives directly to ListLogPlot)? > That would be the simplest solution. > > I can change the color of this part of the graph by going down to the > Graphics element level using Line as in the following, but this is > tedious. > > logY = Map[N[ Log[10, #]] &, yValues] > xyLog = Transpose[{Range[Length[logY]], logY}] > l2 = Graphics[{Red, Thick, Line[Take[xyLog, {3, 6}]]}]; > l1 = Graphics[{Line[Take[xyLog, {1, 3}]]}]; > l3 = Graphics[{Line[Take[xyLog, {6, 10}]]}]; > Show[l1, l2, l3, Axes -> True, AxesOrigin -> {0, 0}] > > Question C. The above graph loses the original Y axis tick values which > are contained in the yValues list defined above. Is there any way to > solve this? I want the graph to look like the first graph above with the > same Y tick values (using ListLogPlot) except the Line segment with X > values from 3 to 6 should be Red. > > Thank you in advance for any help you can give me. > > Don >