Studentenversion des ESY6/A Praktikums "signal_processing".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plot.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. import sys
  3. import os
  4. import pathlib
  5. import matplotlib.pyplot as plt
  6. cwd = pathlib.Path( os.getcwd() )
  7. data_path = cwd.joinpath( 'data.py' )
  8. expected_path = cwd.joinpath( sys.argv[ 1 ] )
  9. if sys.version_info >= ( 3, 6 ):
  10. from importlib.machinery import SourceFileLoader
  11. data = SourceFileLoader( 'data', str( data_path ) ).load_module()
  12. expected = SourceFileLoader( 'expected', str( expected_path ) ).load_module()
  13. elif sys.version_info >= ( 2, 7 ):
  14. import imp
  15. data = imp.load_source( 'data', str( data_path ) )
  16. expected = imp.load_source( 'expected', str( expected_path ) )
  17. else:
  18. sys.stderr.write( 'Error: python version ' + sys.version + ' not supported!\n')
  19. exit( -1 );
  20. if ( len( sys.argv ) != 2 ):
  21. raise( "Usage: {} expected_data.py" )
  22. time_expected = [ i * expected.interval for i in range( len( expected.data ) ) ]
  23. time_actual = [ i * expected.interval for i in range( len( data.float_data ) ) ]
  24. plt.title( expected.title )
  25. plt.plot( time_expected, expected.data, color = 'orange', label = 'expected' )
  26. plt.plot( time_actual, data.float_data, color = 'cornflowerblue', label = 'actual' )
  27. plt.ylabel( 'y' )
  28. plt.xlabel( expected.xlabel )
  29. plt.legend( bbox_to_anchor = ( 0.9, 1.05 ), ncol = 2 )
  30. plt.show()