Input font size can be applied

This commit is contained in:
Ryan Xu 2023-03-06 21:15:07 -08:00
parent 8fb8ae9d4e
commit eb0c60dffb
2 changed files with 10 additions and 7 deletions

View File

@ -20,6 +20,7 @@ class SerialPlotter:
self.settings = json.load(open('settings.json', 'r')) self.settings = json.load(open('settings.json', 'r'))
self.sensors = len(self.settings['sensor_ports']) self.sensors = len(self.settings['sensor_ports'])
self.windowsize = self.settings['winSize'] self.windowsize = self.settings['winSize']
self.fontSize = self.settings['fontSize']
self.delay = self.settings["delay"] / 1000 self.delay = self.settings["delay"] / 1000
self.colors = ['blue', 'orange', 'green', 'yellow'] self.colors = ['blue', 'orange', 'green', 'yellow']
@ -79,19 +80,19 @@ class SerialPlotter:
label=f'sensor {i + 1}, latest: {np.format_float_scientific(self.sensorsData[i][-1], precision = 2)} $\Omega$') label=f'sensor {i + 1}, latest: {np.format_float_scientific(self.sensorsData[i][-1], precision = 2)} $\Omega$')
# Make the font size of values placed on x-axis and y-aixs equal to 16 (large enough) # Make the font size of values placed on x-axis and y-aixs equal to 16 (large enough)
plt.xticks(fontsize = 16) plt.xticks(fontsize = max(self.fontSize, 10))
plt.yticks(fontsize = 16) plt.yticks(fontsize = max(self.fontSize, 10))
# make the label of two axes large enough # make the label of two axes large enough
self.axs.set_xlabel('Time (seconds)', fontsize = 15) self.axs.set_xlabel('Time (seconds)', fontsize = max(self.fontSize, 10))
self.axs.set_ylabel(u'Resistance ($\Omega$)', fontsize = 15) self.axs.set_ylabel(u'Resistance ($\Omega$)', fontsize = max(self.fontSize, 10))
i += 1 i += 1
self.timeElapsed += 1 # increment time self.timeElapsed += 1 # increment time
# Acknowledgement: https://stackoverflow.com/a/13589144 # Acknowledgement: https://stackoverflow.com/a/13589144
handles, labels = self.axs.get_legend_handles_labels() handles, labels = self.axs.get_legend_handles_labels()
by_label = dict(zip(labels, handles)) by_label = dict(zip(labels, handles))
self.axs.legend(by_label.values(), by_label.keys(), loc='best', fontsize = 15) # Make the legend on graph large enough self.axs.legend(by_label.values(), by_label.keys(), loc='best', fontsize = max(self.fontSize, 10)) # Make the legend on graph large enough
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -33,6 +33,7 @@ def main():
port = frame.dev_list.GetValue() port = frame.dev_list.GetValue()
# typical window size: 50 # typical window size: 50
window_size = int(frame.m_textCtrl26.GetValue()) window_size = int(frame.m_textCtrl26.GetValue())
font_size = int(frame.fontSize.GetValue())
#################### END USER INPUTS ######################## #################### END USER INPUTS ########################
@ -46,10 +47,10 @@ def main():
if not (len(resistors) == 5): if not (len(resistors) == 5):
raise ValueError(f"expecting 5 resistor values, but got {len(resistors)}!!!") raise ValueError(f"expecting 5 resistor values, but got {len(resistors)}!!!")
gen_settings(resistors, input_voltage, port, filename, window_size, delay) gen_settings(resistors, input_voltage, port, filename, window_size, font_size, delay)
def gen_settings(resistors, input_voltage, port, filename, window_size, delay): def gen_settings(resistors, input_voltage, port, filename, window_size, font_size, delay):
""" """
export all inputs from main() to a .json file export all inputs from main() to a .json file
:param resistors: list of reference resistances of the sensors :param resistors: list of reference resistances of the sensors
@ -68,6 +69,7 @@ def gen_settings(resistors, input_voltage, port, filename, window_size, delay):
settings["port"] = port settings["port"] = port
# settings["resolution"] = bits # settings["resolution"] = bits
settings["winSize"] = window_size settings["winSize"] = window_size
settings["fontSize"] = font_size
settings["file_name"] = filename settings["file_name"] = filename
settings["delay"] = delay settings["delay"] = delay
open(name, 'w').write(json.dumps(settings, indent=4)) open(name, 'w').write(json.dumps(settings, indent=4))