Быстрый и грязный способ - использовать subplots_adjust
plt.subplots_adjust(bottom=0.2)
![enter image description here](https://i.stack.imgur.com/jmPAd.png)
Это грязно, потому что вы должны вручную поиграться сзначение (например, 0.2
) до тех пор, пока вы не найдете число, которое выглядит правильно.
Но тогда, кажется, что для позиционирования axprev
, axstart
и axnext
.
* 1017 потребовалось некоторое возмущение.*
Лучшим способом было бы расположить оси, используя matplotlib.gridspec.GridSpec
:
import matplotlib.gridspec as gridspec
gs = gridspec.GridSpec(10, 40)
ax = plt.subplot(gs[:7, :])
axprev = plt.subplot(gs[9:, 18:24])
axstart = plt.subplot(gs[9:, 26:32])
axnext = plt.subplot(gs[9:, 34:40])
Например,
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.widgets import Button
import datetime
class Index(object):
def start(self, event=None):
ax.clear()
ax.set_title("Start")
x_values = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
y_values = [10, 20, 15, 1, 5]
ax.set_xticklabels(x_values, rotation=25)
print(ax.get_position())
ax.bar(x_values, y_values)
plt.draw()
def next(self, event):
ax.clear()
ax.set_title("Next")
x_values = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
y_values = [20, 15, 10, 5, 1]
ax.set_xticklabels(x_values, rotation=25)
print(ax.get_position())
ax.bar(x_values, y_values)
plt.draw()
def prev(self, event):
ax.clear()
ax.set_title("Previous")
x_values = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
y_values = [1, 5, 10, 15, 20]
ax.set_xticklabels(x_values, rotation=25)
print(ax.get_position())
ax.bar(x_values, y_values)
plt.draw()
gs = gridspec.GridSpec(10, 40)
ax = plt.subplot(gs[:7, :])
axprev = plt.subplot(gs[9:, 18:24])
axstart = plt.subplot(gs[9:, 26:32])
axnext = plt.subplot(gs[9:, 34:40])
callback = Index()
callback.start()
bprev = Button(axprev, 'Previous')
bprev.on_clicked(callback.prev)
bstart = Button(axstart, 'Start')
bstart.on_clicked(callback.start)
bnext = Button(axnext, 'Next')
bnext.on_clicked(callback.next)
plt.show()
![enter image description here](https://i.stack.imgur.com/MFA29.png)