Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:50

0001 #!/usr/bin/env python
0002 """
0003 steps.py
0004 ===========
0005 
0006 ::
0007 
0008     ipython -i steps.py 
0009 
0010 This demonstrates that should use drawstyle="steps-post"
0011 when plotting rindex as that appears to duplicate the 
0012 last value to give same number of "edges" to "values".
0013 """
0014 import numpy as np
0015 import matplotlib.pyplot as plt
0016 
0017 edges = np.array([0,1,2,3])
0018 values_ = np.array([10,20,30])   
0019 
0020 dupe_last_value = True 
0021 if dupe_last_value:
0022     values = np.zeros( len(values_) + 1 ) 
0023     values[:-1] = values_
0024     values[-1] = values_[-1]
0025 else:
0026     values = values_
0027 pass
0028 
0029 fig,axs = plt.subplots(2,2, figsize=[12.8, 7.2])
0030 ds=[["steps", "steps-pre"],["steps-mid", "steps-post"] ]
0031 
0032 title = " edges : %s   values : %s  dupe_last_value:%s  " % (repr(edges), repr(values), "Y" if dupe_last_value else "N")
0033 print(title)
0034 fig.suptitle( title )
0035 
0036 ylim = [ 0 , values[-1]+10 ]
0037 xlim = [ edges[0]-1, edges[-1]+1 ]
0038 
0039 
0040 for ix in [0,1]:
0041     for iy in [0,1]:
0042         ax = axs[ix,iy]
0043         drawstyle = ds[ix][iy]
0044        
0045         ax.plot( edges, values, drawstyle=drawstyle, label=drawstyle )
0046         ax.scatter( edges, values )
0047 
0048         ax.set_ylim(ylim)
0049         ax.set_xlim(xlim)
0050         ax.legend()
0051 
0052         for e in edges:
0053             ax.plot( [e, e], ylim, linestyle="dotted", color="r")
0054         pass 
0055         for v in values:
0056             ax.plot( xlim, [v,v], linestyle="dotted", color="r")
0057         pass 
0058     pass
0059 pass
0060 
0061 fig.show()  
0062 
0063 
0064