Pyplot contour plot - clabel padding

I have trouble with matplotlib / pyplot / basemap. I plot contour lines (air
pressure) on a map. I use clabel to show the value of the contour lines. But
the problem: the padding between the value and the contour line is too much.
I have found the parameter "inline_spacing", which i have set to zero. But
there is still to much free space. Any ideas?

<http://matplotlib.1069221.n5.nabble.com/file/n44554/mslp.png>

My code is as follows:

Thanks a lot.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi

Your code wans't included, but try setting your x and y limits *before* the call to clabel. I think that the problem is that clabel makes a space in the contours according to how large your font is, but if you then resize the plot (zoom in) then the blank space is too large for the labels.

Cheers, Jody

···

On Dec 4, 2014, at 17:47 PM, Sappy85 <robert.wittkopf@...380...> wrote:

I have trouble with matplotlib / pyplot / basemap. I plot contour lines (air
pressure) on a map. I use clabel to show the value of the contour lines. But
the problem: the padding between the value and the contour line is too much.
I have found the parameter "inline_spacing", which i have set to zero. But
there is still to much free space. Any ideas?

<http://matplotlib.1069221.n5.nabble.com/file/n44554/mslp.png>

My code is as follows:

Thanks a lot.

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554.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=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Jody,

what exactly du you mean - the plot windows size?

I tried this:
fig = plt.figure(figsize=(8.4,5.76))

But still the same problem.

Regards

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554p44557.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I meant plt.xlim and plt.ylim. But its hard to tell what the problem is w/o some sample code.

Cheers, Jody

···

On Dec 5, 2014, at 1:07 AM, Sappy85 <robert.wittkopf@...380...> wrote:

Hi Jody,

what exactly du you mean - the plot windows size?

I tried this:
fig = plt.figure(figsize=(8.4,5.76))

But still the same problem.

Regards

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554p44557.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=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Jody,

i have posted the code. Here again:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import pygrib

filename = "file.grib2"
grbs = pygrib.open('/data/' + filename)
grb = grbs[2]
data = grb.values
datac = data*0.01
lats, lons = grb.latlons()

fig = plt.figure()
m = Basemap(projection='stere',lon_0=5,lat_0=90.0,\
           
llcrnrlon=-25.0,urcrnrlon=60.0,llcrnrlat=30.0,urcrnrlat=60.0,resolution='l')

x, y = m(lons, lats)

levs = range(940,1065,5)
S1=plt.contour(x,y,datac,levs,linewidths=0.5,colors='b')
plt.clabel(S1,inline=1,inline_spacing=0,fontsize=8,fmt='%1.0f',colors='b')

m.drawmapboundary(fill_color='w')
m.drawcoastlines(linewidth=0.2)

plt.savefig('test.png', bbox_inches='tight',pad_inches=0.05, dpi=100)

Regards,
Sappy85

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554p44561.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi @all,
the problem seems to be solved. Thanks Jody!
What i have done:

1.) check out the xlim and ylim after clabel call
*xmin, xmax = plt.xlim() # return the current xlim
ymin, ymax = plt.ylim() # return the current ylim
print xmin,xmax
print ymin,ymax*

2.) use and set these limits before clabel call:
*plt.xlim(0.0,6475051.47849)
plt.ylim(0.0,4412688.31468)*

Yes, that's it. Very confusing! I do not understand why that only goes so
awkward?

Thanks so much!
Sappy85

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554p44582.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Not sure, as I don't use basemap too often, but I bet calling:

m.drawmapboundary(fill_color='w')

before clabel would do the trick

Cheers, Jody

···

On Dec 9, 2014, at 16:35 PM, Sappy85 <robert.wittkopf@...380...> wrote:

Hi @all,
the problem seems to be solved. Thanks Jody!
What i have done:

1.) check out the xlim and ylim after clabel call
*xmin, xmax = plt.xlim() # return the current xlim
ymin, ymax = plt.ylim() # return the current ylim
print xmin,xmax
print ymin,ymax*

2.) use and set these limits before clabel call:
*plt.xlim(0.0,6475051.47849)
plt.ylim(0.0,4412688.31468)*

Yes, that's it. Very confusing! I do not understand why that only goes so
awkward?

Thanks so much!
Sappy85

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554p44582.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=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jody,

perfect - that work's fine.

Regards, Sappy85

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Pyplot-contour-plot-clabel-padding-tp44554p44591.html
Sent from the matplotlib - users mailing list archive at Nabble.com.