首页 > 解决方案 > matplotlib中的文本框太小

问题描述

我正在尝试使用 matplotlib 在我的情节旁边创建一个文本框。问题是文本框没有完全显示在绘图旁边。即使我最大化地块,也是同样的问题

是否有可能以某种方式调整我的绘图区域并使其更小以便文本框可见,并且即使我最大化地块,面积比也会向前推进

import numpy as np
import time
import matplotlib.pyplot as plt

arr_len = 932826
x = np.random.uniform(low=0, high=4496, size=arr_len)
y = np.random.uniform(low=-74, high=492, size=arr_len)
z = np.random.uniform(low=-30, high=97, size=arr_len)

# Check points
bin_x = 10
bin_y = 10
x1 = np.linspace(x.min(), x.max(), bin_x)
y1 = np.linspace(y.min(), y.max(), bin_y)


def return_val(x, y, z, x1, y1, i, j):
    idx = np.logical_and(np.logical_and(x > x1[i - 1], x < x1[i]), np.logical_and(y > y1[j - 1], y < y1[j]))
    if np.count_nonzero(idx) == 0:
        return np.nan
    else:
        # print('X range', x[idx].min(), x[idx].max())
        # print('Y range', y[idx].min(), y[idx].max())
        # print('Z range', z[idx].min(), z[idx].max())
        # plt.plot(x[idx], y[idx], '.')
        # plt.close()
        return np.mean(z[idx])


z1 = np.zeros((len(x1), len(y1)))
for i in range(1, len(x1)):
    for j in range(1, len(y1)):
        z1[i - 1, j - 1] = return_val(x, y, z, x1, y1, i, j)

z1 = z1.transpose()

fig, ax = plt.subplots()
img = ax.pcolormesh(x1, y1, z1)
# cbar = plt.colorbar(img)
textbox = '\n'.join([
    'All plot description goes here: ',
    'File Name: ',
    '',
    'Folder path: ',
    'List of big files processed: ',
    'Dataset name: ',
    '',
    'Filter: ',
    'Grouping: ',
    'Files which are bigger in size than 2000 GB : ',
    '',
    '...',
    '...',
    '...',
])
bbox = dict(boxstyle='square', facecolor='lavender', alpha=0.5)
fig.text(1, 1, textbox, fontsize=10, transform=ax.transAxes, bbox=bbox,
         verticalalignment='top')

在此处输入图像描述

标签: pythonmatplotlib

解决方案


推荐阅读