plot_errband.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Plotting functions with error bands"""
  2. from vedo import np, Rectangle, Text3D, Marker, Line
  3. from vedo.pyplot import plot
  4. # Make up same dummy data
  5. x = np.arange(0, 6, 0.05)
  6. y = 2+2*np.sin(2*x)/(x+1)
  7. ye= y**2 / 10
  8. miny = np.min(y-ye)
  9. idx = np.argmax(y)
  10. # Plot the two variables, return a Plot(Assembly) object:
  11. fig = plot(
  12. x, y,
  13. yerrors=ye,
  14. xtitle='time in :museconds',
  15. ytitle='y oscillation [a.u.]',
  16. ylim=(0.5, 5),
  17. aspect=5/3, # plot aspect ratio (xsize/ysize)
  18. error_band=True, # join errors on y into an error band
  19. lc="red2", # line color
  20. ec="red7", # error band color
  21. padding=0, # no extra spaces around the content
  22. grid=0, # no background grid
  23. axes=dict(axes_linewidth=2, xyframe_line=0),
  24. )
  25. # Add a grey transparent rectangle to represent an exclusion region:
  26. fig += Rectangle([1,0.5], [2.7,5], c='grey5').lighting('off')
  27. # Add some text (set z=2 so it stays on top):
  28. fig += Text3D("Excluded\ntime range!",
  29. s=0.2, c='k', font="Quikhand").rotate_z(20).pos(1.3,3.6)
  30. # Add a star marker at maximum of function (set z=0.1, so it stays on top):
  31. fig += Marker('*', c='blue4').pos(x[idx], y[idx], 0.1)
  32. # Add a dashed line to indicate the minimum
  33. fig += Line((x[0], miny), (x[-1], miny)).pattern('- . -').lw(3)
  34. fig.show(zoom='tight', mode='image', size=(900,600)).close()