Revision: 4940
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4940&view=rev
Author: efiring
Date: 2008-02-04 23:54:01 -0800 (Mon, 04 Feb 2008)
Log Message:
-----------
New example to illustrate log scale for contour levels.
Added Paths:
-----------
trunk/matplotlib/examples/contourf_log.py
Added: trunk/matplotlib/examples/contourf_log.py
===================================================================
--- trunk/matplotlib/examples/contourf_log.py (rev 0)
+++ trunk/matplotlib/examples/contourf_log.py 2008-02-05 07:54:01 UTC (rev
4940)
@@ -0,0 +1,48 @@
+'''
+Demonstrate use of a log color scale in contourf
+'''
+
+from matplotlib import pyplot as P
+import numpy as npy
+from numpy import ma
+from matplotlib import colors, ticker
+from matplotlib.mlab import bivariate_normal
+
+N = 100
+x = npy.linspace(-3.0, 3.0, N)
+y = npy.linspace(-2.0, 2.0, N)
+
+X, Y = npy.meshgrid(x, y)
+
+# A low hump with a spike coming out of the top right.
+# Needs to have z/colour axis on a log scale so we see both hump and spike.
+# linear scale only shows the spike.
+z = (bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0)
+ + 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0))
+
+# Put in some negative values (lower left corner) to cause trouble with logs:
+z[:5, :5] = -1
+
+# The following is not strictly essential, but it will eliminate
+# a warning. Comment it out to see the warning.
+z = ma.masked_where(z<= 0, z)
+
+
+# Automatic selection of levels works; setting the
+# log locator tells contourf to use a log scale:
+cs = P.contourf(X, Y, z, locator=ticker.LogLocator())
+
+# Alternatively, you can manually set the levels
+# and the norm:
+#lev_exp = npy.arange(npy.floor(npy.log10(z.min())-1),
+# npy.ceil(npy.log10(z.max())+1))
+#levs = npy.power(10, lev_exp)
+#cs = P.contourf(X, Y, z, levs, norm=colors.LogNorm())
+
+#The 'extend' kwarg does not work yet with a log scale.
+
+cbar = P.colorbar()
+
+P.show()
+
+
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins