Python Forum
[Tkinter] White edge - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] White edge (/thread-41272.html)



White edge - sdgdfgg - Dec-11-2023

clean Red line region please Heart
[Image: fd2f19dc0bedcac0b35657f266f94f37.jpeg]
root = tk.Tk()
root.title("GeoJSON Viewer")


fig, ax = plt.subplots()
gdf.plot(ax=ax)
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)

animation = FuncAnimation(fig, update_image, frames=range(10), interval=1000)
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.draw()



RE: White edge - deanhystad - Dec-11-2023

Try
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
fig.tight_layout()



RE: White edge - sdgdfgg - Dec-12-2023

(Dec-11-2023, 04:26 PM)deanhystad Wrote: Try
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
fig.tight_layout()
emm I apologize, the result has not changed and there is still whitespace around the plo I made modifications to the code on lines 66 and 53, respectively The following is my complete code
import sys

import tkinter as tk
import hashlib
import random
import threading
import os
import urllib
import requests
import collections

import io
import importlib
import base64
import bs4

import re, string
#from module_a import variable1, variable2

import pygame
# -*- coding: utf-8 -*-。


from tkinter import scrolledtext
from tkinter import END
import copy
import http.client
import time
import datetime
from progress.bar import IncrementalBar


from PIL import Image, ImageTk
import tkinter as tk
import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

from matplotlib.animation import FuncAnimation
import geopandas as gpd
import matplotlib.pyplot as plt
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
#from matplotlib.figure import Figureroot = tk.Tk()
def update_image(frame):

    plt.rcParams['font.sans-serif'] = ['SimHei']  # 设置中文字体为黑体
    plt.rcParams['axes.unicode_minus'] = False  # 
    data = gpd.read_file('{"type":"Feature","properties":{"adcode":130100,"name":"石家庄市","center":[114.502461,38.045474],"centroid":[114.444982,38.133034],"childrenNum":22,"level":"city","subFeatureIndex":0,"acroutes":[100000,130000]},"geometry":{"type":"MultiPolygon","coordinates":[[[[113.839548,38.758413],[113.864664,38.746006],[113.883245,38.74667],[113.932324,38.71362],[113.929697,38.702467],[113.964617,38.699811],[113.991655,38.676769],[114.028624,38.688524],[114.052139,38.686399],[114.086097,38.65837],[114.125053,38.659632],[114.129153,38.669596],[114.182205,38.67657],[114.212831,38.688192],[114.311502,38.706517],[114.341167,38.690184],[114.366411,38.6862],[114.413504,38.703928],[114.437787,38.692773],[114.452652,38.699413],[114.498463,38.678297],[114.522106,38.65372],[114.53633,38.649268],[114.536907,38.632324],[114.552284,38.612983],[114.527616,38.590644],[114.56324,38.590644],[114.58432,38.596429],[114.595724,38.568897],[114.635257,38.514801],[114.651851,38.504682],[114.6737,38.473452],[114.702084,38.489102],[114.731237,38.48191],[114.765259,38.496626],[114.81075,38.492365],[114.830868,38.46033],[114.819143,38.449871],[114.837852,38.435745],[114.840992,38.460797],[114.858163,38.448605],[114.853998,38.435879],[114.882254,38.424149],[114.910381,38.393751],[114.923388,38.388217],[114.932871,38.344194],[114.942994,38.343193],[114.922875,38.315631],[114.906986,38.309624],[114.902565,38.294936],[114.883343,38.284854],[114.886162,38.265286],[114.915059,38.263348],[114.927681,38.283385],[114.970096,38.281114],[114.990087,38.272165],[114.989062,38.258138],[115.031862,38.267089],[115.056465,38.258472],[115.066204,38.264684],[115.056722,38.288326],[115.073765,38.293134],[115.085874,38.276773],[115.108107,38.264551],[115.152317,38.256802],[115.168591,38.259608],[115.19422,38.236759],[115.210174,38.236491],[115.225871,38.269894],[115.252205,38.29093],[115.265788,38.287658],[115.263994,38.260543],[115.273605,38.2403],[115.302758,38.235289],[115.324734,38.248184],[115.323645,38.220586],[115.35094,38.210493],[115.342418,38.196254],[115.346903,38.13967],[115.364843,38.13793],[115.383232,38.0886],[115.420522,38.089671],[115.439871,38.082038],[115.468063,38.095161],[115.482992,38.08398],[115.466782,38.063554],[115.45134,38.017323],[115.438205,38.001102],[115.464219,37.99299],[115.444997,37.989168],[115.456017,37.974551],[115.457555,37.95074],[115.448585,37.936584],[115.412769,37.943293],[115.408668,37.918936],[115.385795,37.917191],[115.365484,37.906318],[115.360294,37.880068],[115.389831,37.874629],[115.388614,37.853003],[115.363049,37.849845],[115.360166,37.820215],[115.349722,37.805765],[115.352349,37.784052],[115.371635,37.770335],[115.344468,37.74814],[115.360294,37.731994],[115.386179,37.727082],[115.394316,37.712143],[115.380989,37.707432],[115.333768,37.71322],[115.317046,37.695383],[115.325567,37.682458],[115.316853,37.660102],[115.301412,37.660169],[115.297376,37.629587],[115.258356,37.639625],[115.255088,37.645621],[115.253807,37.671415],[115.261431,37.68818],[115.243235,37.722641],[115.227281,37.732599],[115.172564,37.749351],[115.152765,37.759507],[115.160262,37.780287],[115.150523,37.808521],[115.131173,37.799783],[115.122972,37.811479],[115.097471,37.807849],[115.097215,37.797498],[115.072291,37.794136],[115.085298,37.779211],[115.068703,37.773428],[115.070049,37.745651],[115.041024,37.733541],[115.012512,37.75157],[115.001748,37.734685],[114.987524,37.742691],[114.960165,37.720084],[114.931846,37.728899],[114.904038,37.729302],[114.895965,37.712547],[114.881357,37.716113],[114.871041,37.702114],[114.847783,37.69673],[114.841504,37.676129],[114.808571,37.659832],[114.797423,37.628239],[114.764618,37.624399],[114.725983,37.630665],[114.707338,37.615774],[114.698816,37.589353],[114.680171,37.565283],[114.64679,37.556247],[114.585217,37.55301],[114.519927,37.574656],[114.483471,37.576814],[114.433495,37.552537],[114.412095,37.549907],[114.37269,37.52967],[114.370192,37.513612],[114.358274,37.519212],[114.334632,37.502949],[114.310861,37.499979],[114.303621,37.507808],[114.27293,37.494445],[114.255439,37.504096],[114.215009,37.51125],[114.184575,37.530817],[114.166123,37.528186],[114.156191,37.505244],[114.133766,37.498899],[114.126526,37.481957],[114.113263,37.493837],[114.096477,37.490935],[114.06899,37.447384],[114.022666,37.435496],[114.028304,37.474598],[114.036762,37.494175],[114.059635,37.515906],[114.118325,37.590634],[114.115378,37.619884],[114.131139,37.648315],[114.139725,37.675927],[114.128256,37.69821],[114.088275,37.708845],[114.068029,37.721564],[113.993769,37.706893],[114.000817,37.735358],[114.041182,37.756817],[114.043873,37.777463],[114.018821,37.794876],[114.006648,37.813495],[113.982557,37.812823],[113.970191,37.833923],[113.971536,37.868786],[113.956864,37.911419],[113.929185,37.932022],[113.922842,37.952082],[113.90125,37.98481],[113.872353,37.990375],[113.878376,38.032402],[113.876261,38.055047],[113.856015,38.065898],[113.854733,38.077082],[113.824235,38.106676],[113.810075,38.112566],[113.822505,38.150442],[113.83359,38.147431],[113.828848,38.168971],[113.796876,38.162884],[113.756575,38.171713],[113.731139,38.168369],[113.720631,38.174656],[113.738507,38.189501],[113.715057,38.193713],[113.711725,38.213702],[113.679112,38.205413],[113.657072,38.225599],[113.636761,38.232682],[113.598894,38.227136],[113.570318,38.237427],[113.566282,38.252393],[113.544818,38.270495],[113.546035,38.293067],[113.557248,38.34346],[113.53431,38.365208],[113.525468,38.383016],[113.538026,38.418017],[113.573202,38.449205],[113.583517,38.465992],[113.546548,38.493031],[113.557248,38.504016],[113.562053,38.558321],[113.602803,38.586854],[113.604212,38.616107],[113.612862,38.646013],[113.632596,38.653122],[113.667067,38.646943],[113.702114,38.65166],[113.713839,38.663684],[113.709995,38.698284],[113.729024,38.71196],[113.745363,38.701538],[113.775669,38.709836],[113.78041,38.728355],[113.802899,38.763321],[113.839548,38.758413]]]]}}')
    data.plot(ax=ax)
    fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
    fig.tight_layout()
gdf = gpd.read_file('{"type":"Feature","properties":{"adcode":130100,"name":"石家庄市","center":[114.502461,38.045474],"centroid":[114.444982,38.133034],"childrenNum":22,"level":"city","subFeatureIndex":0,"acroutes":[100000,130000]},"geometry":{"type":"MultiPolygon","coordinates":[[[[113.839548,38.758413],[113.864664,38.746006],[113.883245,38.74667],[113.932324,38.71362],[113.929697,38.702467],[113.964617,38.699811],[113.991655,38.676769],[114.028624,38.688524],[114.052139,38.686399],[114.086097,38.65837],[114.125053,38.659632],[114.129153,38.669596],[114.182205,38.67657],[114.212831,38.688192],[114.311502,38.706517],[114.341167,38.690184],[114.366411,38.6862],[114.413504,38.703928],[114.437787,38.692773],[114.452652,38.699413],[114.498463,38.678297],[114.522106,38.65372],[114.53633,38.649268],[114.536907,38.632324],[114.552284,38.612983],[114.527616,38.590644],[114.56324,38.590644],[114.58432,38.596429],[114.595724,38.568897],[114.635257,38.514801],[114.651851,38.504682],[114.6737,38.473452],[114.702084,38.489102],[114.731237,38.48191],[114.765259,38.496626],[114.81075,38.492365],[114.830868,38.46033],[114.819143,38.449871],[114.837852,38.435745],[114.840992,38.460797],[114.858163,38.448605],[114.853998,38.435879],[114.882254,38.424149],[114.910381,38.393751],[114.923388,38.388217],[114.932871,38.344194],[114.942994,38.343193],[114.922875,38.315631],[114.906986,38.309624],[114.902565,38.294936],[114.883343,38.284854],[114.886162,38.265286],[114.915059,38.263348],[114.927681,38.283385],[114.970096,38.281114],[114.990087,38.272165],[114.989062,38.258138],[115.031862,38.267089],[115.056465,38.258472],[115.066204,38.264684],[115.056722,38.288326],[115.073765,38.293134],[115.085874,38.276773],[115.108107,38.264551],[115.152317,38.256802],[115.168591,38.259608],[115.19422,38.236759],[115.210174,38.236491],[115.225871,38.269894],[115.252205,38.29093],[115.265788,38.287658],[115.263994,38.260543],[115.273605,38.2403],[115.302758,38.235289],[115.324734,38.248184],[115.323645,38.220586],[115.35094,38.210493],[115.342418,38.196254],[115.346903,38.13967],[115.364843,38.13793],[115.383232,38.0886],[115.420522,38.089671],[115.439871,38.082038],[115.468063,38.095161],[115.482992,38.08398],[115.466782,38.063554],[115.45134,38.017323],[115.438205,38.001102],[115.464219,37.99299],[115.444997,37.989168],[115.456017,37.974551],[115.457555,37.95074],[115.448585,37.936584],[115.412769,37.943293],[115.408668,37.918936],[115.385795,37.917191],[115.365484,37.906318],[115.360294,37.880068],[115.389831,37.874629],[115.388614,37.853003],[115.363049,37.849845],[115.360166,37.820215],[115.349722,37.805765],[115.352349,37.784052],[115.371635,37.770335],[115.344468,37.74814],[115.360294,37.731994],[115.386179,37.727082],[115.394316,37.712143],[115.380989,37.707432],[115.333768,37.71322],[115.317046,37.695383],[115.325567,37.682458],[115.316853,37.660102],[115.301412,37.660169],[115.297376,37.629587],[115.258356,37.639625],[115.255088,37.645621],[115.253807,37.671415],[115.261431,37.68818],[115.243235,37.722641],[115.227281,37.732599],[115.172564,37.749351],[115.152765,37.759507],[115.160262,37.780287],[115.150523,37.808521],[115.131173,37.799783],[115.122972,37.811479],[115.097471,37.807849],[115.097215,37.797498],[115.072291,37.794136],[115.085298,37.779211],[115.068703,37.773428],[115.070049,37.745651],[115.041024,37.733541],[115.012512,37.75157],[115.001748,37.734685],[114.987524,37.742691],[114.960165,37.720084],[114.931846,37.728899],[114.904038,37.729302],[114.895965,37.712547],[114.881357,37.716113],[114.871041,37.702114],[114.847783,37.69673],[114.841504,37.676129],[114.808571,37.659832],[114.797423,37.628239],[114.764618,37.624399],[114.725983,37.630665],[114.707338,37.615774],[114.698816,37.589353],[114.680171,37.565283],[114.64679,37.556247],[114.585217,37.55301],[114.519927,37.574656],[114.483471,37.576814],[114.433495,37.552537],[114.412095,37.549907],[114.37269,37.52967],[114.370192,37.513612],[114.358274,37.519212],[114.334632,37.502949],[114.310861,37.499979],[114.303621,37.507808],[114.27293,37.494445],[114.255439,37.504096],[114.215009,37.51125],[114.184575,37.530817],[114.166123,37.528186],[114.156191,37.505244],[114.133766,37.498899],[114.126526,37.481957],[114.113263,37.493837],[114.096477,37.490935],[114.06899,37.447384],[114.022666,37.435496],[114.028304,37.474598],[114.036762,37.494175],[114.059635,37.515906],[114.118325,37.590634],[114.115378,37.619884],[114.131139,37.648315],[114.139725,37.675927],[114.128256,37.69821],[114.088275,37.708845],[114.068029,37.721564],[113.993769,37.706893],[114.000817,37.735358],[114.041182,37.756817],[114.043873,37.777463],[114.018821,37.794876],[114.006648,37.813495],[113.982557,37.812823],[113.970191,37.833923],[113.971536,37.868786],[113.956864,37.911419],[113.929185,37.932022],[113.922842,37.952082],[113.90125,37.98481],[113.872353,37.990375],[113.878376,38.032402],[113.876261,38.055047],[113.856015,38.065898],[113.854733,38.077082],[113.824235,38.106676],[113.810075,38.112566],[113.822505,38.150442],[113.83359,38.147431],[113.828848,38.168971],[113.796876,38.162884],[113.756575,38.171713],[113.731139,38.168369],[113.720631,38.174656],[113.738507,38.189501],[113.715057,38.193713],[113.711725,38.213702],[113.679112,38.205413],[113.657072,38.225599],[113.636761,38.232682],[113.598894,38.227136],[113.570318,38.237427],[113.566282,38.252393],[113.544818,38.270495],[113.546035,38.293067],[113.557248,38.34346],[113.53431,38.365208],[113.525468,38.383016],[113.538026,38.418017],[113.573202,38.449205],[113.583517,38.465992],[113.546548,38.493031],[113.557248,38.504016],[113.562053,38.558321],[113.602803,38.586854],[113.604212,38.616107],[113.612862,38.646013],[113.632596,38.653122],[113.667067,38.646943],[113.702114,38.65166],[113.713839,38.663684],[113.709995,38.698284],[113.729024,38.71196],[113.745363,38.701538],[113.775669,38.709836],[113.78041,38.728355],[113.802899,38.763321],[113.839548,38.758413]]]]}}')

# 创建 Tkinter 窗口
root = tk.Tk()
root.title("GeoJSON Viewer")


# 创建一个 Matplotlib 画布
fig, ax = plt.subplots()
gdf.plot(ax=ax)
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)

fig.tight_layout()
animation = FuncAnimation(fig, update_image, frames=range(30), interval=1000)
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.draw()


canvas.get_tk_widget().pack(fill=tk.BOTH, expand=True)
tk.mainloop()
The result is..

[Image: 624f86e2c03be9e0c37cdc70f42bcc85.jpeg]


RE: White edge - deanhystad - Dec-12-2023

Try isolating the problem. Instead of plotting in a tkinter window, let pyplot draw a window for the plot. If you plot has wide margins you know this is something going on with geopandas. If the plot looks find in a pyplot then there is something going on with tkinter and the layout.

If this is a tkinter layout problem I would put the plot canvas in a frame with a border so you can see the edge of the plot canvas. Is the wide margin inside our outside the frame?


RE: White edge - reneejenkins - Dec-14-2023

Try to isolate the issue. Instead of charting in a tkinter window, let pyplot create a plot window.