sg.Input获取y轴数据代码
sg.Text('First Read:', font=("Times New Roman", 9)),sg.Input(key='-first_read-', size=(25, 1), default_text='0,0,0', justification='center', font=("Times New Roman", 9), expand_x=True), sg.Text('Second Read:', font=("Times New Roman", 9)),sg.Input(key='-second_read-', size=(25, 1), default_text='0,0,0', justification='center', font=("Times New Roman", 9), expand_x=True),
数据解析
data_list_first = value_fpr_plot["-first_read-"].split(',')data_list_second = value_fpr_plot["-second_read-"].split(',')
画图
plt.clf() # 清除当前图形的所有轴,通常用于在绘制新图形之前清除上一个图形。colors = list(mcolors.XKCD_COLORS.keys())marker = [".", "2", "x", "o", "*", "s", "3", "4", "+", "d"]data_list = []data_list.append(data_list_first)data_list.append(data_list_second)y_ticks = int(max([max(t) for t in data_list]))x_ticks = range(0, len(data_list[0]) * 10, 10)for i in range(len(data_list)):plt.plot(x_ticks, data_list[i], lw=1, ls='-', c=mcolors.XKCD_COLORS[colors[i]], marker=".", alpha=0.9, label=read_legend[i])plt.yticks(arange(0, y_ticks + 1, ceil(y_ticks / 15)), fontsize=7)
数据输入
图片输出
原因
经过value_fpr_plot["-first_read-"].split(',')
解析的数据会变为[‘1’,‘2’,‘3’]的形式,列表中的数据已经由预期的int变为str形式,进而使用该数据画图导致yticks错乱。
代码修改
plt.clf() # 清除当前图形的所有轴,通常用于在绘制新图形之前清除上一个图形。colors = list(mcolors.XKCD_COLORS.keys())marker = [".", "2", "x", "o", "*", "s", "3", "4", "+", "d"]data_list = []data_list.append([int(i) for i in data_list_first]) #修改data_list.append([int(i) for i in data_list_second])#修改y_ticks = int(max([max(t) for t in data_list]))x_ticks = range(0, len(data_list[0]) * 10, 10)for i in range(len(data_list)):plt.plot(x_ticks, data_list[i], lw=1, ls='-', c=mcolors.XKCD_COLORS[colors[i]], marker=".", alpha=0.9, label=read_legend[i])plt.yticks(arange(0, y_ticks + 1, ceil(y_ticks / 15)), fontsize=7)