Search code examples
pythonplotidl-programming-language

How to generate the lineared color plot (cplot) with z values in colorbar


In MATLAB™ one can use cplot.m which can generate colored plot basically looks like 2d plot with 3rd axis (z-axis) value as colorbar. Is there any tool/plotting technique I can use to generate a similar plot in Python or IDL Programming Language?. The previous question on stack overflow dealing with different problem as given in a link.

cplot image (Linear colored line plot


Solution

  • IDL v8 has an easy to use keyword for the PLOT function called VERT_COLORS:

    ; generate some sample data
    x = cos(dindgen(100)/20)
    y = sin(dindgen(100)/20)
    z = dindgen(100)+100
    
    ; plot the data
    p = plot(x, y, vert_colors=bytscl(z), rgb_table=39, xrange=[-2,2], yrange=[-2,2], thick=3, /aspect_ratio)
    cb = colorbar(range=[min(z), max(z)], target=p)
    

    plot with colorbar

    The z data is scaled to a byte index of the colortable number 39. The colorbar needs to know the data range explicitly.