I am using Python 2.7 and plotting using matplotlib package. I have a plot with legend at top. When i try to zoom the plot window to see more information in the plot, sometimes the legend moves out of the window. I am not able to figure out why this happens. This does not happen all the time though. I have attached the code. The lists x11,x22...., temp11,...temp25 and humi11,...humi25 are data from database. The plot is displayed correctly. However i am facing issues with strange situation of legend moving out of plot window. I have also attached the portion of the image for your reference. Kindly provide your insights.
This is the normal view of the plot.
.
This is the view of the plot after zooming. See the part of the legend is visible on the corner of window.
Regards
Sriniketh
import matplotlib
import matplotlib.pyplot as plt,mpld3
import matplotlib.dates as mdates
import numpy as np
from matplotlib.backends.backend_tkagg importFigureCanvasTkAgg,NavigationToolbar2TkAgg
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import tkMessageBox
from drawnow import *
from Tkinter import *
import Tkinter as tk
from tkinter import ttk
from dateutil.parser import parse
import decimal
plt.subplot(211)
plt.title('Temperatur')
plt.plot((x11), (temp11), 'ro-', label='M1-Node 1')
plt.plot((x12), (temp12), 'go-', label='M1-Node 2')
plt.plot((x13), (temp13), 'bo-', label='M1-Node 3')
plt.plot((x14), (temp14), 'co-', label='M1-Node 4')
plt.plot((x15), (temp15), 'mo-', label='M1-Node 5')
plt.plot((x21), (temp21), 'ro--', label='M2-Node 1')
plt.plot((x22), (temp22), 'go--', label='M2-Node 2')
plt.plot((x23), (temp23), 'bo--', label='M2-Node 3')
plt.plot((x24), (temp24), 'co--', label='M2-Node 4')
plt.plot((x25), (temp25), 'mo--', label='M2-Node 5')
plt.ylabel('Temperatur Grad C')
# plt.legend(loc='upper left')
plt.legend(bbox_to_anchor=(0.985, 0.89),
bbox_transform=plt.gcf().transFigure)
plt.grid(True)
plt.subplot(212)
plt.title('Relativ Luftfeuchtigkeit')
plt.plot((x11), (humi11), 'ro-', label='M1-Node 1')
plt.plot((x12), (humi12), 'go-', label='M1-Node 2')
plt.plot((x13), (humi13), 'bo-', label='M1-Node 3')
plt.plot((x14), (humi14), 'co-', label='M1-Node 4')
plt.plot((x15), (humi15), 'mo-', label='M1-Node 5')
plt.plot((x21), (humi21), 'rd-', label='M2-Node 1')
plt.plot((x22), (humi22), 'gd-', label='M2-Node 2')
plt.plot((x23), (humi23), 'bd-', label='M2-Node 3')
plt.plot((x24), (humi24), 'cd-', label='M2-Node 4')
plt.plot((x25), (humi25), 'md-', label='M2-Node 5')
plt.ylabel('Relativ Luftfeuchtigkeit')
plt.grid(True)
master = var1.get()
plt.suptitle("Temperatur und Luftfeuchtigkeit - %s " % (master))
plt.show()