亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 tkinter 窗口上的圖像上顯示帶有線條的圖像?

如何在 tkinter 窗口上的圖像上顯示帶有線條的圖像?

素胚勾勒不出你 2022-07-05 17:00:07
該程序讀取位于位置 C:/Square.png 的圖像,并在其上繪制線條。情節標題也被定義。我想在 tkinter 窗口中顯示整個圖像。我該怎么做?這是圖像。名稱必須更改,我們可以運行代碼。 https://imgur.com/RkV02yYimport mathimport matplotlib.pyplot as pltdef plot_output(opt_w, opt_h, n_x, n_y):    y_start, y_end = 100, 425    x_start, x_end = 25, 400    img = plt.imread("C:/Square.png") #Please change the location    fig, ax = plt.subplots(figsize=(10, 10))    plt.axis('off')    ax.imshow(img)    x_interval = (x_end - x_start)/n_x*2    h_x = range(x_start, x_end, 5)    for i in range(0,int(n_y)):        if i != 0:            ax.plot(h_x, [y_start + (y_end-y_start)/n_y*i]*len(h_x), '--', linewidth=5, color='firebrick')    plt.title(str(int(n_x*n_y)) + ' ABCD\n'+'TYUI:'+str(opt_w)+', Yummy:'+str(opt_h))def get_get(min_w, min_h, max_w, max_h, PL, PH, min_t, max_t, cost_m, cost_a):    x = 1    if max_w < PL:        x = math.ceil(PL / max_w)    cost_rest = cost_m * PL * PH * (max_t + min_t) / 2 + cost_a * PH * x    cost_y = float("inf")    y = None    if min_h == 0:        min_h = 1    for i in range(math.ceil(PH / max_h), math.floor(PH / min_h)+1):        tmp_cost = cost_m * PL * PH * (max_t - min_t) / 2 / i + cost_a * PL * i        if tmp_cost < cost_y:            cost_y = tmp_cost            y = i    opt_w, opt_h, opt_cost = PL/x, PH/y, cost_rest + cost_y    plot_output(opt_w, opt_h, x, y)    return opt_w, opt_h, opt_costPL=30PH=10min_t=0.1max_t=0.3cost_m=0.1cost_a=0.1min_w=0.5min_h=0.5max_w=4max_h=3get_get(min_w, min_h, max_w, max_h, PL, PH, min_t, max_t, cost_m, cost_a)
查看完整描述

1 回答

?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

您需要添加 plt.show()


import math

import matplotlib.pyplot as plt

import matplotlib

matplotlib.use("Tkagg")


def plot_output(opt_w, opt_h, n_x, n_y):

    y_start, y_end = 100, 425

    x_start, x_end = 25, 400


    img = plt.imread("C:/Square.png") #Please change the location

    fig, ax = plt.subplots(figsize=(10, 10))

    plt.axis('off')

    ax.imshow(img)


    x_interval = (x_end - x_start)/n_x*2


    h_x = range(x_start, x_end, 5)

    for i in range(0,int(n_y)):

        if i != 0:

            ax.plot(h_x, [y_start + (y_end-y_start)/n_y*i]*len(h_x), '--', linewidth=5, color='firebrick')

    plt.title(str(int(n_x*n_y)) + ' ABCD\n'+'TYUI:'+str(opt_w)+', Yummy:'+str(opt_h))

    plt.show()


def get_get(min_w, min_h, max_w, max_h, PL, PH, min_t, max_t, cost_m, cost_a):

    x = 1

    if max_w < PL:

        x = math.ceil(PL / max_w)

    cost_rest = cost_m * PL * PH * (max_t + min_t) / 2 + cost_a * PH * x


    cost_y = float("inf")

    y = None

    if min_h == 0:

        min_h = 1

    for i in range(math.ceil(PH / max_h), math.floor(PH / min_h)+1):

        tmp_cost = cost_m * PL * PH * (max_t - min_t) / 2 / i + cost_a * PL * i

        if tmp_cost < cost_y:

            cost_y = tmp_cost

            y = i


    opt_w, opt_h, opt_cost = PL/x, PH/y, cost_rest + cost_y

    plot_output(opt_w, opt_h, x, y)

    return opt_w, opt_h, opt_cost


PL=30

PH=10

min_t=0.1

max_t=0.3

cost_m=0.1

cost_a=0.1

min_w=0.5

min_h=0.5

max_w=4

max_h=3


get_get(min_w, min_h, max_w, max_h, PL, PH, min_t, max_t, cost_m, cost_a)

編輯:我忘記將后端更改為 tkinter


查看完整回答
反對 回復 2022-07-05
  • 1 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號