如何获取 xtick 主要标签的位置?我从 label.get_position() 获得的值没有意义。
import numpy as np
import matplotlib.pyplot as plt
def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)
t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)
# fig, ax = plt.figure(1)
fig, ax = plt.subplots()
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
# plt.show()
print(fig)
print(ax.get_position())
# ------------------------------------------------
# positions of the tick labels, incorrect (0,0) returned
# ------------------------------------------------
print([text.get_position() for text in ax.get_xticklabels()])
# correct tick label values
print(ax.get_xticks())
Run Code Online (Sandbox Code Playgroud)
上述代码的输出是:
Figure(640x480)
Bbox('array([[ 0.125,  0.1  ],\n       [ 0.9 …Run Code Online (Sandbox Code Playgroud) 更新:在 memory_profiler 版本 0.53 及更高版本中,可以 @profile 装饰任意数量的路由。早期版本只允许装饰一条路线。以下问题仅适用于版本 <= 0.52 的 memory_profiler 版本
使用普通的@profile装饰器不适用于两个或多个 Flask 路由。如何在两个或多个 Flask 路由中逐行获取内存使用情况分析?
我想分析 /route_one 和 /route_two:
from functools import wraps
from memory_profiler import profile
@app.route("/route_one", methods=["GET"])
@profile
def route_one():
    api_live = ping_api()
    if not api_live:
        return make_response('', 503)
    return make_response('', 200)
@app.route("/route_two", methods=["GET"])
@profile
def route_two():
    api_live = ping_api()
    if not api_live:
        return make_response('', 503)
    return make_response('', 200)
Run Code Online (Sandbox Code Playgroud)
当我使用上述装饰路线启动我的烧瓶应用程序时,我收到此错误:
AssertionError: View function mapping is overwriting an existing endpoint function: wrapper
Run Code Online (Sandbox Code Playgroud)