<s> from matplotlib . collections import LineCollection <EOL> import matplotlib . pyplot as plt <EOL> import numpy as np <EOL> from bokeh import mpl <EOL> from bokeh . plotting import output_file , show <EOL> def make_segments ( x , y ) : <EOL> '''<STR_LIT>''' <EOL> points = np . array ( [ x , y ] ) . T . reshape ( - <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> segments = np . concatenate ( [ points [ : - <NUM_LIT:1> ] , points [ <NUM_LIT:1> : ] ] , axis = <NUM_LIT:1> ) <EOL> return segments <EOL> def colorline ( x , y , colors = None , linewidth = <NUM_LIT:3> , alpha = <NUM_LIT:1.0> ) : <EOL> '''<STR_LIT>''' <EOL> colors = [ '<STR_LIT:r>' , '<STR_LIT:g>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:y>' , '<STR_LIT:m>' , '<STR_LIT:k>' ] <EOL> widths = [ <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT:10> , <NUM_LIT:5> ] <EOL> segments = make_segments ( x , y ) <EOL> lc = LineCollection ( segments , colors = colors , linewidth = widths , alpha = alpha ) <EOL> ax = plt . gca ( ) <EOL> ax . add_collection ( lc ) <EOL> return lc <EOL> x = np . linspace ( <NUM_LIT:0> , <NUM_LIT:4> * np . pi , <NUM_LIT:100> ) <EOL> y = np . sin ( x ) <EOL> colorline ( x , y ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . xlim ( x . min ( ) , x . max ( ) ) <EOL> plt . ylim ( - <NUM_LIT:1.0> , <NUM_LIT:1.0> ) <EOL> output_file ( "<STR_LIT>" , title = "<STR_LIT>" ) <EOL> show ( mpl . to_bokeh ( ) ) </s>
