Quantcast
Viewing all articles
Browse latest Browse all 14215

Edit axis. Matplotlib

I am trying to edit my axis's graphic but it is not working when I use plt.yticks([]). The program is still showing me the values. Can you help me remove them?

Maybe the problem is because I am using canvas?

import tkinter as tkimport matplotlib.pyplot as pltfrom matplotlib.figure import Figurefrom matplotlib.backends.backend_tkagg import FigureCanvasTkAggfrom matplotlib import animationimport random# Create the Tkinter windowroot = tk.Tk()root.geometry('400x100')fig1, b1 = plt.subplots(figsize=(10, 0.5), dpi = 80,)b1 = fig1.add_subplot(111)plt.yticks([])fig2, b2 = plt.subplots(figsize= (10, 0.5), dpi = 80)b2 = fig2.add_subplot(111)plt.yticks([])def grafico_1 (i):    global b1    global nume    global valu    global fig1    global y_fix    global x    x = []    y_fix = []    ws = ['WIRE']    for valu in range (1, 6):        nume = random.randint(1, 10)        x.append(nume)    #print(x)    #Primeira camada do grafico     if int(x[0]) < 3:        y_fix.append(int(x[0]))        #print(f'Lista de y_n ,e {y_n}')        b1.barh(ws, int(x[0]), color = 'green')    if int(x[0]) >= 3 and int(x[0]) < 6:        y_fix.append(x[0])        b1.barh(ws, int(x[0]), color = 'yellow' )    if int(x[0]) >= 6:        y_fix.append(x[0])        b1.barh(ws, int(x[0]), color= 'red' )    #Segunda camada:    for c in x[1:]:        if int(c) < 3 :            b1.barh(ws, int(c), color= 'green', left=y_fix)            y_fix.append(int(c))            jump = sum(y_fix)            y_fix = []            y_fix.append(jump)        if int(c) > 3 and int(c) < 5:            b1.barh(ws, int(c), color='yellow', left= y_fix)            y_fix.append(int(c))            jump = sum(y_fix)            y_fix = []            y_fix.append(jump)        if int(c) >= 5:            b1.barh(ws, int(c), color='red', left= y_fix)            y_fix.append(int(c))            jump = sum(y_fix)            y_fix = []            y_fix.append(jump)    #fig1 = plt.yticks([])def grafico_2 (i2):    global b2    global nume2    global valu2    global fig2    global y_fix2    global x2    x2 = []    y_fix2 = []    ws2 = ['line 2']    for valu2 in range (1, 6):        nume2 = random.randint(1, 10)        x2.append(nume2)    #print(f'Grafico 2 {x2}')    #Primeira camada do grafico     if int(x2[0]) < 3:        y_fix2.append(int(x2[0]))        #print(f'Lista de y_n ,e {y_n}')        b2.barh(ws2, int(x2[0]), color = 'green')    if int(x2[0]) >= 3 and int(x2[0]) < 6:        y_fix2.append(x2[0])        b2.barh(ws2, int(x2[0]), color = 'yellow' )    if int(x2[0]) >= 6:        y_fix2.append(x2[0])        b2.barh(ws2, int(x2[0]), color= 'red' )    #Segunda camada:    for c2 in x2[1:]:        if int(c2) < 3 :            b2.barh(ws2, int(c2), color= 'green', left=y_fix2)            y_fix2.append(int(c2))            jump2 = sum(y_fix2)            y_fix2 = []            y_fix2.append(jump2)        if int(c2) > 3 and int(c2) < 5:            b2.barh(ws2, int(c2), color='yellow', left= y_fix2)            y_fix2.append(int(c2))            jump2 = sum(y_fix2)            y_fix2 = []            y_fix2.append(jump2)        if int(c2) >= 5:            b2.barh(ws2, int(c2), color='red', left= y_fix2)            y_fix2.append(int(c2))            jump2 = sum(y_fix2)            y_fix2 = []            y_fix2.append(jump2)    #plt.show()ani1 = animation.FuncAnimation(fig1, grafico_1, interval = 3000, frames=100)ani2 = animation.FuncAnimation(fig2, grafico_2, interval = 3000, frames=100)# Embed the figures into Tkinter using FigureCanvasTkAggcanvas1 = FigureCanvasTkAgg(fig1, master=root)canvas1.get_tk_widget().place(x= 300, y= 460)canvas2 = FigureCanvasTkAgg(fig2, master=root)canvas2.get_tk_widget().place(x= 300, y = 530)root.mainloop()

I could remove the values from my x and y axes.


Viewing all articles
Browse latest Browse all 14215

Trending Articles