小编Jas*_*ang的帖子

Figure.show 仅适用于 pyplot 管理的图形

有关于使用matplotlib.pyplotmatplotlib 3.5.1 的错误报告,所以我尝试使用它matplotlib.figure.Figure来绘制图形并且它工作正常。

Figure当我无法调用时,如何在 matplotlib 中查看图形plt.show?调用fig.show会出现以下异常:

Traceback (most recent call last):
  File "<module1>", line 23, in <module>
  File "C:\Software\Python\lib\site-packages\matplotlib\figure.py", line 2414, in show
    raise AttributeError(
AttributeError: Figure.show works only for figures managed by pyplot, normally created by pyplot.figure()
Run Code Online (Sandbox Code Playgroud)

显示此问题的演示代码:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure

x = np.linspace(0, 10, 500)
y = np.sin(x**2)+np.cos(x)

# ------------------------------------------------------------------------------------

fig, ax = plt.subplots()
ax.plot(x, y, label ='Line 1')
ax.plot(x, …
Run Code Online (Sandbox Code Playgroud)

python matplotlib figure

5
推荐指数
1
解决办法
1012
查看次数

如何在 tkinter 中查看树视图的部分区域和水平滚动?

我有一个由 tk.treeview 创建的表,例如,有 10 列。目标是构建一个带有水平滚动条的树形视图小部件,小部件的视图宽度设置为大约 4 列,并使用水平滚动条查看其他列。

使用 tk.Frame 作为父窗口小部件并使用滚动条,垂直滚动将隐藏标题,因此不要使用它。

平台:WIN 10 Python:3.8.6 tkinter:8.6

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

# root.columnconfigure(0, weight=1)
# root.rowconfigure(0, weight=1)

columns = [f'Column {i}' for i in range(10)]

x_scrollbar = tk.Scrollbar(root, orient=tk.HORIZONTAL)
x_scrollbar.grid(row=1, column=0, sticky=tk.E+tk.W)
y_scrollbar = tk.Scrollbar(root, orient=tk.VERTICAL)
y_scrollbar.grid(row=0, column=1, sticky=tk.N+tk.S)

tree = ttk.Treeview(root, columns=columns, height=10, show="headings",
    xscrollcommand=x_scrollbar.set, yscrollcommand=y_scrollbar.set)
tree.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)

for col in tree['columns']:
        tree.heading(col, text=f"{col}", anchor=tk.CENTER)
        tree.column(col, anchor=tk.CENTER, width=100)

for i in range(100):
    tree.insert('', 'end', …
Run Code Online (Sandbox Code Playgroud)

python treeview tkinter

3
推荐指数
1
解决办法
2004
查看次数

标签 统计

python ×2

figure ×1

matplotlib ×1

tkinter ×1

treeview ×1