A bin folder, holding helpfull scripts and commands
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mkgnuplot 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. import math
  4. import jinja2
  5. import optparse
  6. import os
  7. import shutil
  8. import time
  9. example_gnuplot = """
  10. set terminal wxt
  11. #set xdata time # tells gnuplot the x axis is time data
  12. #set timefmt '%s' # specify our time string format
  13. #set format x '%H' # otherwise it will show only MM:SS
  14. set title "GnuPlot Example"
  15. set xlabel "X"
  16. set ylabel "Y"
  17. set key autotitle columnhead
  18. set datafile separator ','
  19. plot 'example.csv' using 1:2 with lines title "title 1", \
  20. '' using 1:3 with lines title "title 2", \
  21. '' using 1:2 with lines, \
  22. '' using 1:3 with lines
  23. pause -1 "Hit any key to continue"
  24. """
  25. example_csv = "x, sin(x)/x, sin(x)\n"
  26. for i in range (-500, 500):
  27. x = 3* i * math.pi / 500
  28. f2_x = math.sin(x)
  29. if x == 0:
  30. f1_x = 1
  31. else:
  32. f1_x = f2_x / x
  33. example_csv += "%f, %f, %f\n" % (x, f1_x, f2_x)
  34. def mkdir(path):
  35. """.. warning:: Needs to be documented
  36. """
  37. path=os.path.abspath(path)
  38. if not os.path.exists(os.path.dirname(path)):
  39. mkdir(os.path.dirname(path))
  40. if not os.path.exists(path):
  41. os.mkdir(path)
  42. return os.path.isdir(path)
  43. if __name__ == "__main__":
  44. parser = optparse.OptionParser("usage: %%prog [options] folder_for_document")
  45. parser.add_option("-f", "--force", dest="force", action="store_true", default=False)
  46. (options, args) = parser.parse_args()
  47. if len(args) != 1:
  48. parser.print_help()
  49. else:
  50. target_path = os.path.join(os.path.abspath('.'), args[0])
  51. #
  52. # Main Actions
  53. #
  54. if not os.path.exists(target_path) or options.force:
  55. mkdir(target_path)
  56. with open(os.path.join(target_path, 'example.gnuplot'), 'w+') as fh:
  57. fh.write(example_gnuplot)
  58. with open(os.path.join(target_path, 'example.csv'), 'w+') as fh:
  59. fh.write(example_csv)
  60. else:
  61. print("Folder exists. Use option -f to force creation")