[Matplotlib-users] Legend cut off figure

2015-05-22 Thread njs
I've tried several methods on stackoverflow
(http://stackoverflow.com/questions/10101700/moving-matplotlib-legend-outside-of-the-axis-makes-it-cutoff-by-the-figure-box)
and I'm still seeing issues with matplotlib cutting off my legend.  The
figure and code are posted below, note that I am using 

fig.savefig(fname,bbox_extra_artists = (lgd,),bbox_inches = tight)  

Also, the legend handler doesn't appear to be working correctly and the
suptitle get's cut off which makes me think there's something major I'm
messing up that I haven't yet found. Oddly, adding fig.tight_layout() causes
overlap and the legend to get pulled back inside the figure (see second
figure).

Note that I'm also using mpl 1.4.3.  Thanks for any help offered, and
apologies for asking a question that has appeared many times!

Nick

http://matplotlib.1069221.n5.nabble.com/file/n45595/idp_brier_scores.jpeg 
http://matplotlib.1069221.n5.nabble.com/file/n45595/idp_brier_scores_tightlayout.jpeg
 

import matplotlib.pyplot as plt
import numpy as np
import datetime as dt
import h5py as h5
from matplotlib.legend_handler import HandlerLine2D
from matplotlib.ticker import MultipleLocator,FormatStrFormatter

majorLocator   = MultipleLocator(5)
majorFormatter = FormatStrFormatter('%d')
minorLocator   = MultipleLocator(1)
LagLabel = ['','-3 to 3','2 to 8','7 to 13','12 to 18','17 to 23','22 to
28','27 to 33']

rc = plt.rcParams
rc['font.family'] = 'arial'

rc['xtick.direction'] = 'out'
rc['xtick.major.width'] = 2
rc['xtick.labelsize'] = 'medium'
rc['ytick.major.width'] = 2
rc['ytick.direction'] = 'out'
rc['ytick.labelsize'] = 'medium'

rc['grid.linewidth'] = 1
rc['grid.linestyle'] = ':'

#rc['axes.labelweight'] = 'regular'
rc['axes.linewidth'] = 2
rc['axes.labelsize'] = 'large'

rc['legend.fancybox'] = True


fig,ax = plt.subplots(3,1,sharex = True)
fig.subplots_adjust(right = 0.75)
l1, = ax[0].plot(BSBin1[0,:],linewidth = 2,color = '#66c2a5',
marker = 'o',label = varNames[0])
l2, = ax[0].plot(BSBin1[1,:],linewidth = 2,color = '#fc8d62',
marker = 'o',label = varNames[1])
l3, = ax[0].plot(BSBin1[2,:],linewidth = 2,color = '#8da0cb',
marker = 'o',label = varNames[2])
l4, = ax[0].plot(BSBin1[3,:],linewidth = 2,color = '#e78ac3',
marker = 'o',label = varNames[3])
l5, = ax[0].plot(BSBin1[4,:],linewidth = 2,color = '#a6d854',
marker = 'o',label = varNames[4])

l1, = ax[1].plot(BSBin2[0,:],linewidth = 2,color = '#66c2a5',
marker = 'o',label = varNames[0])
l2, = ax[1].plot(BSBin2[1,:],linewidth = 2,color = '#fc8d62',
marker = 'o',label = varNames[1])
l3, = ax[1].plot(BSBin2[2,:],linewidth = 2,color = '#8da0cb',
marker = 'o',label = varNames[2])
l4, = ax[1].plot(BSBin2[3,:],linewidth = 2,color = '#e78ac3',
marker = 'o',label = varNames[3])
l5, = ax[1].plot(BSBin2[4,:],linewidth = 2,color = '#a6d854',
marker = 'o',label = varNames[4])

l1, = ax[2].plot(BSBin3[0,:],linewidth = 2,color = '#66c2a5',
marker = 'o',label = varNames[0])
l2, = ax[2].plot(BSBin3[1,:],linewidth = 2,color = '#fc8d62',
marker = 'o',label = varNames[1])
l3, = ax[2].plot(BSBin3[2,:],linewidth = 2,color = '#8da0cb',
marker = 'o',label = varNames[2])
l4, = ax[2].plot(BSBin3[3,:],linewidth = 2,color = '#e78ac3',
marker = 'o',label = varNames[3])
l5, = ax[2].plot(BSBin3[4,:],linewidth = 2,color = '#a6d854',
marker = 'o',label = varNames[4])

l6, = ax[0].plot(BSClimo1,linewidth = 2,color = 'k',
marker = 'o',label = 'Climo')
l6, = ax[1].plot(BSClimo2,linewidth = 2,color = 'k',
marker = 'o',label = 'Climo')
l6, = ax[2].plot(BSClimo3,linewidth = 2,color = 'k',
marker = 'o',label = 'Climo')

# Set Titles
ax[0].set_title('a. Below Normal',fontsize = 12)
ax[1].set_title('b. Normal',fontsize = 12)
ax[2].set_title('c. Above Normal',fontsize = 12)
ax[1].set_ylabel('Brier Score')
ax[2].set_xlabel('Lag')

ax[0].grid(True); ax[1].grid(True); ax[2].grid(True)
ax[0].set_ylim((.1,.25)); ax[1].set_ylim((.1,.25));
ax[2].set_ylim((.1,.25))

ax[2].set_xticks(np.arange(0,31,5))
ax[2].xaxis.set_major_locator(majorLocator)
ax[2].xaxis.set_minor_locator(minorLocator)
ax[2].xaxis.set_ticks_position('bottom')
ax[2].set_xticklabels(LagLabel,rotation = 45,ha = 'right')
ax[0].xaxis.set_ticks_position('bottom')
ax[1].xaxis.set_ticks_position('bottom')
ax[2].xaxis.set_ticks_position('bottom')
plt.suptitle('{0} Brier Score | 1979-2013'.format(season),fontsize = 14,
fontweight = 'bold')  

handles,labels = ax[0].get_legend_handles_labels()
lgd = fig.legend(handles,labels,bbox_to_anchor = (1.05,.75),loc =
'center right',
handler_map = {l1: 

[Matplotlib-users] quiverkey() doesn't plot the reference vector?

2015-02-18 Thread njs
Hi All,

I'm having issues with quiver, and quiverkey() although, I have never
experienced these issues in the past.  I attached an image to this post that
demonstrates that quiver_key() used to work for me, this image was generated
on 17-Jul-2014.  However, if I run this exact same code (see below for the
code), the quiver key reference on the top right does not get plotted, but
the text will.  I haven't changed anything, but I think there have been some
package updates between then and now.  For what it's worth, I've tried many
different ways to generate the quiverkey() and haven't had any luck.  Has
anyone else experienced similar issues? 

Thanks for any insights!

Working quiverkey():
http://matplotlib.1069221.n5.nabble.com/file/n44968/qkey.png 

quiverkey() doesn't work anymore...:
http://matplotlib.1069221.n5.nabble.com/file/n44968/qkey_1.png 

Code:

fig = plt.figure(figsize=(12,12))
map = Basemap(projection = 'cyl', llcrnrlat = -30, urcrnrlat = 90, \
llcrnrlon = 0, urcrnrlon = 360, resolution = 'c')   
 
[x,y] = N.meshgrid(lons,lats)
[x,y] = map(x,y)
[xulr,yulr] = N.meshgrid(lons1,lats1)
[xulr,yulr] = map(xulr,yulr)
clevs = N.arange(-50,51,5)
cs = map.contourf(x,y,hgt500aComp[lag,:,:],cmap='RdBu_r',
levels = clevs)
cs1 = map.contour(x,y,hgt500Comp[lag,:,:],N.arange(1110,1230,6), \
colors='purple',linewidth=100,linestyle = 'dashed')
cs1 = map.contour(x,y,hgt500aComp[lag,:,:],levels = clevs,
colors = 'black')
   
colors=[(244,2,255),(36,26,232),(255,255,255),(8,232,61),(224,255,0)]
cmap = mF.make_cmap(colors, position=None, bit=True)
clevs = N.arange(-30,30.025,.025)   
cs2 = map.contourf(xulr,yulr,olrComp[lag,:,:],cmap=cmap,
levels = clevs)
Q = map.quiver(x[::2,::2],y[::2,::2],u850Comp[lag,::2,::2],
v850Comp[lag,::2,::2],width = 0.002,scale = 50)
map.drawcoastlines(linewidth = 1)
map.drawcountries(linewidth = 0.5)
map.fillcontinents(zorder = 0)
map.drawmeridians(N.arange(0,360,30))
map.drawparallels(N.arange(-90,90,30))
title = plt.title('Lag: {0} | Transition Cases | n =
{1}'.format(lag-30,len(cases)))
title.set_fontweight('bold')
axt = fig.add_axes([.15,.35,.3,.01])
cbar = plt.colorbar(cs,cax = axt,orientation = 'horizontal')
cbar.set_label('500-hPa Anomaly (m)')
cbar.set_ticks(N.arange(-50,51,25))
cs1.clabel(fmt = '%d')
axt = fig.add_axes([.58,.35,.3,.01])
cbar2 = plt.colorbar(cs2,cax = axt,orientation = 'horizontal')
cbar2.set_label(r'OLR Anomaly ($W m^{-2}$)')
cbar2.set_ticks(N.arange(-30,31,10))
qk = plt.quiverkey(Q,0.95,1.05,1.0,r'1 $m s^{-1}$',labelpos='E')



--
View this message in context: 
http://matplotlib.1069221.n5.nabble.com/quiverkey-doesn-t-plot-the-reference-vector-tp44968.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

--
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration  more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631iu=/4140/ostg.clktrk
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users