Code Search for Developers
 
 
  

contour_demo.py from matplotlib at Krugle


Show contour_demo.py syntax highlighted

#!/usr/bin/env python
'''
Illustrate simple contour plotting, contours on an image with
a colorbar for the contours, and labelled contours.

See also contour_image.py.
'''
from pylab import *

rcParams['xtick.direction'] = 'out'
rcParams['ytick.direction'] = 'out'

delta = 0.025
x = arange(-3.0, 3.0, delta)
y = arange(-2.0, 2.0, delta)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)



# Create a simple contour plot with labels using default colors.  The
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label
figure()
CS = contour(X, Y, Z)
clabel(CS, inline=1, fontsize=10)
title('Simplest default with labels')


# You can force all the contours to be the same color.
figure()
CS = contour(X, Y, Z, 6,
             colors='k', # negative contours will be dashed by default
             )
clabel(CS, fontsize=9, inline=1)
title('Single color - negative contours dashed')

# You can set negative contours to be solid instead of dashed:
rcParams['contour.negative_linestyle'] = 'solid'
figure()
CS = contour(X, Y, Z, 6,
             colors='k', # negative contours will be dashed by default
             )
clabel(CS, fontsize=9, inline=1)
title('Single color - negative contours solid')


# And you can manually specify the colors of the contour
figure()
CS = contour(X, Y, Z, 6,
             linewidths=arange(.5, 4, .5),
             colors=('r', 'green', 'blue', (1,1,0), '#afeeee', '0.5')
             )
clabel(CS, fontsize=9, inline=1)
title('Crazy lines')


# Or you can use a colormap to specify the colors; the default
# colormap will be used for the contour lines
figure()
im = imshow(Z, interpolation='bilinear', origin='lower',
            cmap=cm.gray, extent=(-3,3,-2,2))
levels = arange(-1.2, 1.6, 0.2)
CS = contour(Z, levels,
             origin='lower',
             linewidths=2,
             extent=(-3,3,-2,2))

#Thicken the zero contour.
zc = CS.collections[6]
setp(zc, linewidth=4)

clabel(CS, levels[1::2],  # label every second level
       inline=1,
       fmt='%1.1f',
       fontsize=14)

# make a colorbar for the contour lines
CB = colorbar(CS, shrink=0.8, extend='both')

title('Lines with colorbar')
hot()  # Now change the colormap for the contour lines and colorbar
flag()

# We can still add a colorbar for the image, too.
CBI = colorbar(im, orientation='horizontal', shrink=0.8)

# This makes the original colorbar look a bit out of place,
# so let's improve its position.

l,b,w,h = gca().get_position()
ll,bb,ww,hh = CB.ax.get_position()
CB.ax.set_position([ll, b+0.1*h, ww, h*0.8])


#savefig('contour_demo')
show()




See more files for this project here

matplotlib

Matplotlib is a pure python plotting library with the goal of making\r\npublication quality plots using a syntax familiar to matlab users. \r\nThe library uses Numeric for handling large\r\ndata sets and supports a variety of output backends

Project homepage: http://sourceforge.net/projects/matplotlib
Programming language(s): C,C++,Python
License: other

  data/
  units/
  widgets/
  README
  README.wx
  __init__.py
  accented_text.py
  agg_buffer_to_array.py
  agg_oo.py
  agg_resize.py
  agg_test.py
  alignment_test.py
  anim.py
  anim_tk.py
  animation_blit.py
  animation_blit_fltk.py
  animation_blit_qt.py
  animation_blit_qt4.py
  animation_blit_tk.py
  animation_blit_wx.py
  annotation_demo.py
  anscombe.py
  arctest.py
  arrow_demo.py
  axes_demo.py
  axes_props.py
  axhspan_demo.py
  axis_equal_demo.py
  backend_driver.py
  bar_stacked.py
  barchart_demo.py
  barcode_demo.py
  barh_demo.py
  boxplot_demo.py
  break.py
  broken_barh.py
  clippath_test.py
  clippedline.py
  collections_demo.py
  color_by_yvalue.py
  color_demo.py
  colorbar_only.py
  colours.py
  contour_demo.py
  contour_image.py
  contourf_demo.py
  coords_demo.py
  coords_report.py
  csd_demo.py
  cursor_demo.py
  custom_figure_class.py
  custom_ticker1.py
  customize_rc.py
  dannys_example.py
  dash_control.py
  dashpointlabel.py
  dashtick.py
  data_browser.py
  data_helper.py
  date_demo1.py
  date_demo2.py
  date_demo_convert.py
  date_demo_rrule.py
  date_index_formatter.py
  dynamic_collection.py
  dynamic_demo.py
  dynamic_demo_wx.py
  dynamic_image_gtkagg.py
  dynamic_image_wxagg.py
  dynamic_image_wxagg2.py
  ellipse_demo.py
  ellipse_rotated.py
  embedding_in_gtk.py
  embedding_in_gtk2.py
  embedding_in_gtk3.py
  embedding_in_qt.py
  embedding_in_qt4.py
  embedding_in_tk.py
  embedding_in_tk2.py
  embedding_in_wx.py
  embedding_in_wx2.py
  embedding_in_wx3.py
  embedding_in_wx4.py
  errorbar_demo.py
  errorbar_limits.py
  figimage_demo.py
  figlegend_demo.py
  figtext.py
  fill_between.py
  fill_between_posneg.py
  fill_demo.py
  fill_demo2.py
  fill_spiral.py
  finance_demo.py
  font_indexing.py
  font_table_ttf.py
  fonts_demo.py
  fonts_demo_kw.py
  ftface_props.py
  ganged_plots.py
  gdtest.py