Уменьшить расстояние до края. Matplotlib
Подскажите, пожалуйста, как уменьшить расстояние между краями графика и краями окна?
Можно ли контролировать каждую сторону отдельно?
import matplotlib.pyplot as mpl
arr = []
for i in range(0, 16):
arr.append(i)
fig = mpl.figure(figsize=(16,9))
ax = fig.add_subplot(1, 1, 1)
ax.get_xaxis().set_visible(False)
ax.tick_params(axis = 'y', labelsize = 8.5)
ax.barh(arr, arr)
mpl.show()
Ответы (2 шт):
Автор решения: S. Nick
→ Ссылка
Попробуйте так:
import matplotlib.pyplot as mpl
arr = []
for i in range(0, 16):
arr.append(i)
margins = { # +++
"left" : 0.040,
"bottom" : 0.060,
"right" : 0.990,
"top" : 0.990
}
fig = mpl.figure(figsize=(16,9))
fig.subplots_adjust(**margins) # +++
ax = fig.add_subplot(1, 1, 1)
ax.get_xaxis().set_visible(False)
ax.tick_params(axis = 'y', labelsize = 8.5)
ax.barh(arr, arr)
mpl.show()
Автор решения: passant
→ Ссылка
Возможно также вот так (цифры разумеется приведены просто для демонстрации возможностей и их надо подбирать в конкретном случае):
import matplotlib
matplotlib.rcParams['figure.subplot.left'] = 0.01
matplotlib.rcParams['figure.subplot.bottom'] = 0.1
matplotlib.rcParams['figure.subplot.right'] = 0.5
matplotlib.rcParams['figure.subplot.top'] =0.5

