Suppose you have the dataset
xData = Table[i, {i, 1, 30}];
yData = RandomReal[{0.995, 1.005}, 30];
and want to plot the difference of yData-1
on a ListLogPlot
.
ListLogPlot[Transpose[{xData, yData - 1}], Joined -> True, Mesh -> All]
Of course, there will be negative differences, hence not being plotted. If the differences' signs were unimportant one could just plot Abs[yData-1]
. However, if the sign is important: What is a (I am sure there must be something) nice way to e.g. plot the Abs
but use different markers for different signs. The only way I can come up with is pre-processing the data into two sets corresponding to the signs and then plot both seperately into the same graph.
Edit: I decided to accept MichaelE2's answer because I did not know anything about VertexColor
and it could be very useful for future plotting issues. However, also all other answers are great solutions and I don't mean to depreciate their value by not accepting them - I just think that one answer should be accepted to "close" the question.
Answer
You can use VertexColors
to color the individual points, since the points are all in a single Point
in order.
ListLogPlot[Transpose[{xData, Abs[yData - 1]}], Joined -> True, Mesh -> All] /.
Point[p_] :>
Point[p, VertexColors -> (Sign[yData - 1] /. {1 -> Black, -1 -> Red, 0 -> Blue})]
Threw in the 0
case even though 0
won't be plotted by ListLogPlot
. One could have it print a warning, too.
Comments
Post a Comment