1
$\begingroup$

I am plotting three lists of different size on the same plot. I want the plot to start from zero rather than 1 on the x-axis. In the past, I have used DataRange->{0,Max} to achieve this, but in this case the data range of all lists is changed, which is not what I want.

For example, consider:

a = {1, 2, 3};
b = {2, 3, 4, 5, 6};
c = {3, 4, 5, 6, 7, 8, 9, 10};

ListLogPlot[{a, b, c}, Joined -> True, PlotLegends -> {"a", "b", "c"}]

which yields:

If I add in the DataRange requirement, ListLogPlot[{a, b, c}, Joined -> True, PlotMarkers -> {"a", "b", "c"}, PlotLegends -> {"a", "b", "c"}, DataRange -> {0, 7}], I get the following plot, where all my lists are stretched to span the range 0->7:

I want each list to start at zero, but preserve its range (so 0->2 for a, 0-> 4 for b, etc. ). I am plotting them all together rather than creating different plots because I need the legend.

$\endgroup$
  • 3
    $\begingroup$ You could provide the x coordinate you want explicitly, like a->Transpose[{Range[0, Length[a]-1], a}] and so on. $\endgroup$ – b.gates.you.know.what Oct 27 at 14:07
  • $\begingroup$ That does the trick - thanks! $\endgroup$ – Rossana Oct 27 at 14:11
2
$\begingroup$

You can use TemporalData with time spec Automatic to get uniformly spaced times starting at 0:

td = TemporalData[{a, b, c}, Automatic];

ListLogPlot[td, Joined -> True, 
  PlotLegends -> {"a", "b", "c"}, 
  PlotMarkers -> (Style[#, 14, Background -> White] & /@ {"a", "b", "c"})]

enter image description here

Use TimeSeriesRescale to modify time ranges:

ListLogPlot[TimeSeriesRescale[td, {10, 12}] , 
 Joined -> True, PlotLegends -> {"a", "b", "c"},
 PlotMarkers -> (Style[#, 14, Background -> White] & /@ {"a", "b", "c"})]

enter image description here

| improve this answer | |
$\endgroup$
0
$\begingroup$
a = {1, 2, 3};
b = {2, 3, 4, 5, 6};
c = {3, 4, 5, 6, 7, 8, 9, 10}; 
ListLogPlot[
 Table[MapIndexed[{First[#2] - 1, #1} &, x], {x, {a, b, c}}], 
 Joined -> True, DataRange -> {0, 7}, PlotMarkers -> {"a", "b", "c"}, 
 PlotLegends -> {"a", "b", "c"}]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.