Question: order of curves in a plot

May 16 2014 itsme 324

2


Say I have some function that cannot be changed and it returns this:

all_plots:=display([plot(sin(10*x+0.2),x=0..1, thickness=10, color=blue), plot(1-sin(10*x),x=0..1, thickness=10, color=red), plot(sin(10*x),x=0..1, thickness=10, color=green)]):


Now can plot it as:
plots:-display( all_plots );


...but what if I need the (say) red curve to be "on top" (fully visible), green curve in the middle, and blue curve at the bottom (as is now).

what is the most effective way to do this?

EDIT:

i guess this works:

display([convert(all_plots, list)[1], convert(all_plots, list)[3],  convert(all_plots, list)[2]]);

EDIT 2:

... lookst like above doesn't keep all the extra options that a plot can have... here is a version that seems to do it.

rearrangeCurves:=proc(v_items, v_reorder:=[])
  #Reorder should be a list of index pairs like
  #[[3,5], [-1, 1], ...]
  local p, temp, curves:=[], rest:=[]:
  #separate curves from rest (there must be a prettier way to do this)
  for p in convert(v_items, list) do
    if type(p,'function') and op(0,p) = ('CURVES') then 
      curves:=[curves[], p]:
    else
      rest:=[rest[], p]:
    end;
  end;
  #now reorder
  for p in v_reorder do
    temp:=curves[p[1]]:
    curves[p[1]]:=curves[p[2]]:
    curves[p[2]]:=temp:
  end;
  PLOT(curves[], rest[]):
end:

#change say second last with last curve:

rearrangeCurves(all_plots, [[-2, -1]]);

 

Please Wait...