cleanup for plot export and copy

This commit is contained in:
Xevion
2019-10-27 16:41:43 -05:00
parent 2c7417cb5a
commit 48798de547

View File

@@ -2,6 +2,7 @@ import os
import sys import sys
import json import json
import logging import logging
import datetime
import collections import collections
import numpy as np import numpy as np
import dateutil.parser import dateutil.parser
@@ -65,14 +66,25 @@ def process_data(data):
plt.xlabel('Month') plt.xlabel('Month')
plt.xticks(ind, months, rotation=270) # Rotation 90 will have the plt.xticks(ind, months, rotation=270) # Rotation 90 will have the
plt.legend((p1[0], p2[0]), ('Explicit', 'Safe')) plt.legend((p1[0], p2[0]), ('Explicit', 'Safe'))
# plt.show() logging.info('Showing plot to User')
copy(months, safe, explicit) plt.show()
# Save the figure, overwriting anything in your way
logging.info('Saving the figure to the \'export\' folder')
export_folder = os.path.join(sys.path[0], 'export')
if not os.path.exists(export_folder):
os.makedirs(export_folder)
plt.savefig(os.path.join(export_folder, datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')))
# Copy the figure to your clipboard to paste in Excel
# logging.info('Copying the plot data to clipboard')
# copy(months, safe, explicit)
# Simple method for exporting data to a table like format # Simple method for exporting data to a table like format
# Will paste into Excel very easily # Will paste into Excel very easily
def copy(months, safe, explicit): def copy(months, safe, explicit):
from pyperclip import copy from pyperclip import copy
top = 'period\tsafe\texplicit\n' top = 'Period\tSafe\tExplicit\n'
copy(top + '\n'.join([ copy(top + '\n'.join([
f'{item[0]}\t{item[1]}\t{item[2]}' for item in zip(months, safe, explicit) f'{item[0]}\t{item[1]}\t{item[2]}' for item in zip(months, safe, explicit)
])) ]))