|
From: Karl E. <kt...@ma...> - 2006-09-05 15:58:01
Attachments:
BadColorBar.png
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hello,<br>
<br>
I am trying to construct a contour plot where the contours are
separated by a constant amount but I would like a color bar (or
something) to show what the values of the different levels are. I will
have too many contours for clabels to be effective.<br>
<br>
When I use colorbar with unequally spaced contours and use
cspacing='linear' the ticks are spaced nicely but the colors are not.<br>
<br>
The following code exemplifies the problem:<br>
<br>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Kate, the KDE Advanced Text Editor">
<pre><span style="color: rgb(128, 128, 128);"><i>#!/usr/bin/python</i></span>
<span style="color: rgb(255, 0, 255);">from</span> pylab <span
style="color: rgb(255, 0, 255);">import</span> <span
style="color: rgb(255, 0, 255);">*</span>
<span style="color: rgb(128, 128, 128);"><i>#Compute Data</i></span>
delta <span
style="color: rgb(255, 0, 255);">=</span> <span
style="color: rgb(128, 0, 128);">0.025</span>
x <span
style="color: rgb(255, 0, 255);">=</span> arange<span
style="color: rgb(255, 0, 255);">(-</span><span
style="color: rgb(128, 0, 128);">3.0</span>, <span
style="color: rgb(128, 0, 128);">3.0</span>, delta<span
style="color: rgb(255, 0, 255);">)</span>
y <span
style="color: rgb(255, 0, 255);">=</span> arange<span
style="color: rgb(255, 0, 255);">(-</span><span
style="color: rgb(128, 0, 128);">2.0</span>, <span
style="color: rgb(128, 0, 128);">2.0</span>, delta<span
style="color: rgb(255, 0, 255);">)</span>
X, Y <span
style="color: rgb(255, 0, 255);">=</span> meshgrid<span
style="color: rgb(255, 0, 255);">(</span>x, y<span
style="color: rgb(255, 0, 255);">)</span>
Z1 <span
style="color: rgb(255, 0, 255);">=</span> bivariate_normal<span
style="color: rgb(255, 0, 255);">(</span>X, Y, <span
style="color: rgb(128, 0, 128);">1.0</span>, <span
style="color: rgb(128, 0, 128);">1.0</span>, <span
style="color: rgb(128, 0, 128);">0.0</span>, <span
style="color: rgb(128, 0, 128);">0.0</span><span
style="color: rgb(255, 0, 255);">)</span>
Z2 <span
style="color: rgb(255, 0, 255);">=</span> bivariate_normal<span
style="color: rgb(255, 0, 255);">(</span>X, Y, <span
style="color: rgb(128, 0, 128);">1.5</span>, <span
style="color: rgb(128, 0, 128);">0.5</span>, <span
style="color: rgb(0, 0, 255);">1</span>, <span
style="color: rgb(0, 0, 255);">1</span><span
style="color: rgb(255, 0, 255);">)</span>
<span style="color: rgb(128, 128, 128);"><i># difference of Gaussians</i></span>
Z <span
style="color: rgb(255, 0, 255);">=</span> <span
style="color: rgb(128, 0, 128);">100.0</span> <span
style="color: rgb(255, 0, 255);">*</span> <span
style="color: rgb(255, 0, 255);">(</span>Z2 <span
style="color: rgb(255, 0, 255);">-</span> Z1<span
style="color: rgb(255, 0, 255);">)</span>
<span style="color: rgb(128, 128, 128);"><i>#Draw figure</i></span>
figure<span
style="color: rgb(255, 0, 255);">()</span>
levels<span
style="color: rgb(255, 0, 255);">=[-</span><span
style="color: rgb(0, 0, 255);">9</span>,<span
style="color: rgb(255, 0, 255);">-</span><span
style="color: rgb(128, 0, 128);">7.5</span>,<span
style="color: rgb(255, 0, 255);">-</span><span
style="color: rgb(0, 0, 255);">5</span>,<span
style="color: rgb(255, 0, 255);">-</span><span
style="color: rgb(128, 0, 128);">2.5</span>,<span
style="color: rgb(255, 0, 255);">-</span><span
style="color: rgb(128, 0, 128);">0.5</span>,<span
style="color: rgb(128, 0, 128);">0.5</span>,<span
style="color: rgb(128, 0, 128);">2.5</span>,<span
style="color: rgb(0, 0, 255);">5</span>,<span
style="color: rgb(128, 0, 128);">7.5</span>,<span
style="color: rgb(0, 0, 255);">9</span><span
style="color: rgb(255, 0, 255);">]</span>
CS <span
style="color: rgb(255, 0, 255);">=</span> contour<span
style="color: rgb(255, 0, 255);">(</span>Z, levels,
origin<span
style="color: rgb(255, 0, 255);">=</span><span
style="color: rgb(221, 0, 0);">'lower'</span>,
linewidths<span
style="color: rgb(255, 0, 255);">=</span><span
style="color: rgb(0, 0, 255);">2</span>,
extent<span
style="color: rgb(255, 0, 255);">=(-</span><span
style="color: rgb(0, 0, 255);">3</span>,<span
style="color: rgb(0, 0, 255);">3</span>,<span
style="color: rgb(255, 0, 255);">-</span><span
style="color: rgb(0, 0, 255);">2</span>,<span
style="color: rgb(0, 0, 255);">2</span><span
style="color: rgb(255, 0, 255);">))</span>
clabel<span
style="color: rgb(255, 0, 255);">(</span>CS,
inline<span
style="color: rgb(255, 0, 255);">=</span><span
style="color: rgb(0, 0, 255);">1</span>,
fmt<span
style="color: rgb(255, 0, 255);">=</span><span
style="color: rgb(221, 0, 0);">'%1.1f'</span>,
fontsize<span
style="color: rgb(255, 0, 255);">=</span><span
style="color: rgb(0, 0, 255);">14</span><span
style="color: rgb(255, 0, 255);">)</span>
colorbar<span
style="color: rgb(255, 0, 255);">(</span>CS,cspacing<span
style="color: rgb(255, 0, 255);">=</span><span
style="color: rgb(221, 0, 0);">'linear'</span><span
style="color: rgb(255, 0, 255);">)</span> <span
style="color: rgb(128, 128, 128);"><i># make a colorbar for the contour lines</i></span>
title<span
style="color: rgb(255, 0, 255);">(</span><span
style="color: rgb(221, 0, 0);">"ColorBar lines don't match ticks"</span><span
style="color: rgb(255, 0, 255);">)</span>
savefig<span
style="color: rgb(255, 0, 255);">(</span><span
style="color: rgb(221, 0, 0);">'BadColorBar'</span><span
style="color: rgb(255, 0, 255);">)</span>
show<span
style="color: rgb(255, 0, 255);">()</span>
</pre>
<br>
I have attached the file 'BadColorBar.png'<br>
<br>
Any help would be appreciated,<br>
Karl Edler<br>
</body>
</html>
|
|
From: Eric F. <ef...@ha...> - 2006-09-05 18:05:41
Attachments:
BadColorBar.png
linecbar.py
|
Karl Edler wrote: > Hello, > > I am trying to construct a contour plot where the contours are separated > by a constant amount but I would like a color bar (or something) to show > what the values of the different levels are. I will have too many > contours for clabels to be effective. > > When I use colorbar with unequally spaced contours and use > cspacing='linear' the ticks are spaced nicely but the colors are not. Karl, This was fixed some time ago with completely new colorbar code, including a change in the API. Attached are a modification of your test program to suit the API (and make a smaller png file for this email), and the result. Eric |