有没有办法在不使用ax2 = ax.twinx的情况下使我的代码适应Tkinter gui以添加第二个y轴

问题描述

我有一个gui,上面有很多选项卡和不同的图,到目前为止,我已经使用了一种类似于下面的方法(这是代码的最小化部分,但是如果您尝试将无法运行,只是作为说明)。

我已经看到ax2=ax.twinx()是这样做的一种方法,但是我不知道如何重新配置​​我的代码而不重新启动它,是否还有另一种方法还是我只需要重新配置从头开始密谋?

部分代码

#MAKE A figURE OBJECT
my_figure = figure(figsize = (6,6),dpi = 100) 
#MAKE A FRAME WIDGET
frame1_trap = tk.Frame(tab4,bd=2,relief=tk.GROOVE)
#MAKE A SECOND FRAME WIDGET
frame2_trap = tk.Frame(tab4,relief=tk.GROOVE)

#pack frames to preserve button sizes while canvas frame is resized
frame2_trap.pack(side=tk.RIGHT,anchor=tk.E,fill=tk.BOTH)
frame1_trap.pack(side=tk.LEFT,anchor=tk.N,fill=tk.BOTH,expand=True)

#MAKE A CANVAS OBJECT
my_canvas = figureCanvasTkAgg(my_figure,master = frame1_trap) # creating the Tkinter canvas containing the Matplotlib figure  

# TURN THE CANVAS OBJECT INTO A CANVAS WIDGET
my_canvas.get_tk_widget().pack(side="top",fill='both',expand=True) # placing the canvas on the Tkinter window and making it resize with the window
my_canvas.draw()


def plot_frequency_sweep():
    my_figure.clear()
    my_canvas.draw_idle()

    my_plot = my_figure.add_subplot(111) # adding the subplot
    
    my_plot.scatter(x=df["x-data"],y= df["A-data"],marker='.',c='none',edgecolor='b',label = 'A-data')
    my_plot.scatter(x=df["x-data"],y= df["B-data"],edgecolor='r',label = 'B-data')
    my_plot.set_xticks(np.arange(freq_axis_origin,freq_axis_max,10))
    my_plot.set_yticks(np.arange(vel_axis_origin,vel_axis_max,1))
    my_plot.set_facecolor('xkcd:light gray')

    # LOGIC FOR  PLOT
    # get current C data method
    if C_method()==0:
        #how to plot a secondary y xis??
        my_plot.scatter(x=df["x-data"],y= df["C-data"],label = 'C-data')

    my_plot.set_title('sweep ' + fileOPW,fontsize=10,fontweight='bold')
    my_plot.set_xlim([user_start_freq,user_end_freq])
    my_plot.set_ylim([vel_axis_origin,vel_axis_max])
    my_plot.grid(True,linestyle='--')
    my_plot.legend(loc = "upper right")
    my_canvas.draw()

root.mainloop()
root.destroy()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...