Re: Controling the color of line segments in a Log plot

*To*: mathgroup at smc.vnet.net*Subject*: [mg90171] Re: Controling the color of line segments in a Log plot*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Tue, 1 Jul 2008 07:00:30 -0400 (EDT)*References*: <g4a6r8$8s5$1@smc.vnet.net>

Donald DuBois wrote: > 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? It does not use base 10. The tick labels are the actual values, not the logarithms (i.e. it uses 10^6 and not 6). > > 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. Yes, it is possible with Mesh and related options. ListLogPlot[xy, Joined -> True, Mesh -> {{3, 6}}, MeshShading -> {Blue, Red, Blue}(*,MeshStyle->None*)] Check the doc page of the Mesh* options, and also the examples related to these options on the doc pages of various plotting functions. (They were not completely intuitive to me until I checked the examples.) > > 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. > Well, maybe this is little cheating but, I think that the simplest solution would be to extract the tick specifications from the original graphic and use them in the Show function above: gr = ListLogPlot[xy, Joined -> True] myLogTicks = Ticks /. AbsoluteOptions[gr, Ticks] Show[ ..., Ticks -> myLogTicks] (This may need some adjustments before it will look right if you use a different plot range in Show than in gr.) > Thank you in advance for any help you can give me. > > Don >