diff --git a/utils/plot_json_export/.gitignore b/utils/plot_json_export/.gitignore index 68bc17f..7a154e7 100644 --- a/utils/plot_json_export/.gitignore +++ b/utils/plot_json_export/.gitignore @@ -158,3 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + + +out.png diff --git a/utils/plot_json_export/plot_json_export.py b/utils/plot_json_export/plot_json_export.py index 2b3ecce..e19569a 100644 --- a/utils/plot_json_export/plot_json_export.py +++ b/utils/plot_json_export/plot_json_export.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import json, numpy as np, matplotlib.pyplot as plt +import orjson, numpy as np, matplotlib.pyplot as plt def color_int2tuple(colorint): # https://stackoverflow.com/a/2262152, License https://creativecommons.org/licenses/by-sa/2.5/ @@ -12,13 +12,13 @@ def main(argv): return 1 filename = argv[1] try: - file = open(filename, "r") + file = open(filename, "rb") except IOError: print("Error opening file.") raise else: with file: - data = json.load(file) + data = orjson.loads(file.read()) assert "map" in data, "Invalid JSON savefile format" plts = np.array(tuple(tuple(color_int2tuple(int(c)) for c in r) for r in data["map"]), dtype=np.uint8) if len(argv) >= 3: @@ -34,11 +34,11 @@ def main(argv): plts = np.rot90(plts, axes = (0,1)) case "-90" | "270" | "+270": plts = np.rot90(plts, k = -1, axes = (0,1)) + plt.figure(facecolor=(0, 0, 0)) plt.imshow(plts) - try: - plt.show() - except KeyboardInterrupt: - pass + plt.axis('off') + plt.savefig('out.png', bbox_inches='tight') + print("Image saved at out.png.") return 0 if __name__ == "__main__": diff --git a/utils/plot_json_export/requirements.txt b/utils/plot_json_export/requirements.txt new file mode 100644 index 0000000..89fa62b --- /dev/null +++ b/utils/plot_json_export/requirements.txt @@ -0,0 +1,12 @@ +contourpy==1.1.0 +cycler==0.11.0 +fonttools==4.42.1 +kiwisolver==1.4.5 +matplotlib==3.7.2 +numpy==1.25.2 +orjson==3.9.5 +packaging==23.1 +Pillow==10.0.0 +pyparsing==3.0.9 +python-dateutil==2.8.2 +six==1.16.0