English 中文(简体)
从轴心中删除数字
原标题:remove the number from the y axis

我正试图将我的轴线照相,但我没有使用<代码>plt.yps([])。 该方案正在向我展示价值观。 你们能否帮助我ed,请? 也许问题在于,我正在使用“血管”,我试图将<条码>(......)放到他中间,但甚至没有工作。

Below my code:

import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib import animation
import random

# Create the Tkinter window
root = tk.Tk()
root.geometry( 400x100 )

fig1, b1 = plt.subplots(figsize=(10, 0.5), dpi = 80,)
b1 = fig1.add_subplot(111)


fig2, b2 = plt.subplots(figsize= (10, 0.5), dpi = 80)
b2 = fig2.add_subplot(111)



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) 
            
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 FigureCanvasTkAgg
canvas1 = 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()





1. 在轴心中创造无任何数字的图形

问题回答

在这方面,你可以如何处理这一问题:

  1. 直接为每一次部署制定标准: 你们需要将一套标准(标准)方法用在你想要修改的具体轴心上(如果是的话,是b1和b2)。

  2. Ensure consistent axes usage: It looks like you re redefining b1 and b2 after creating them. When you use b1 = fig1.add_subplot(111), it s not necessary to create fig1, b1 = plt.subplots() beforehand; you can directly create the subplot.

更新的法典实例:

import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib import animation
import random

# Create the Tkinter window
root = tk.Tk()
root.geometry( 400x100 )

fig1 = plt.Figure(figsize=(10, 0.5), dpi=80)
b1 = fig1.add_subplot(111)

fig2 = plt.Figure(figsize=(10, 0.5), dpi=80)
b2 = fig2.add_subplot(111)

# ... [rest of your code remains the same until the grafico_1 and grafico_2 functions]

def grafico_1(i):
    global b1
    # ... [rest of your code for grafico_1]

    # Clear previous axes and set y-ticks to an empty list
    b1.clear()
    b1.set_yticks([])

    # ... [rest of your plotting code for grafico_1]

def grafico_2(i2):
    global b2
    # ... [rest of your code for grafico_2]

    # Clear previous axes and set y-ticks to an empty list
    b2.clear()
    b2.set_yticks([])

    # ... [rest of your plotting code for grafico_2]

# ... [rest of your code for animations and canvas]

root.mainloop()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签