Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-27 Thread David Smith
 
julia include(plotnan.jl) 
INFO: Loading help data... 
/Users/dss/anaconda/lib/python2.7/site-packages/matplotlib/colors.py:583: 
RuntimeWarning: invalid value encountered in less 
cbook._putmask(xa, xa  0.0, -1) 
PyObject matplotlib.collections.PolyCollection object at 0x11993b4d0


This is the code:
  
using PyPlot 
x = rand(8,8)
x[1] = NaN 
pcolor(x)

On Wednesday, November 26, 2014 8:05:32 AM UTC-6, Steven G. Johnson wrote:



 On Wednesday, November 26, 2014 12:45:09 AM UTC-5, David Smith wrote:

 My up-to-date version of Matplotlib won't plot NaNs either.


 That's weird; it works fine for me in Matplotlib 1.4.0.

 In any case, you can always zero out the NaN values in W via:
 W[isnan(W)] = 0
 before plotting. 



Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-27 Thread David Smith
Sorry, forgot the version.  That was 

matplotlib1.4.0np19py27_0 


Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-26 Thread Steven G. Johnson


On Wednesday, November 26, 2014 12:45:09 AM UTC-5, David Smith wrote:

 My up-to-date version of Matplotlib won't plot NaNs either.


That's weird; it works fine for me in Matplotlib 1.4.0.

In any case, you can always zero out the NaN values in W via:
W[isnan(W)] = 0
before plotting. 


Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-26 Thread Pileas
I found out that the code works when I use IJulia, but not when I run the 
command: julia file.jl.

This is weird indeed ...

Τη Τετάρτη, 26 Νοεμβρίου 2014 9:05:32 π.μ. UTC-5, ο χρήστης Steven G. 
Johnson έγραψε:



 On Wednesday, November 26, 2014 12:45:09 AM UTC-5, David Smith wrote:

 My up-to-date version of Matplotlib won't plot NaNs either.


 That's weird; it works fine for me in Matplotlib 1.4.0.

 In any case, you can always zero out the NaN values in W via:
 W[isnan(W)] = 0
 before plotting. 



[julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread David Smith
Also consider using for loops to eliminate the need for storage of 
intermediates.  For loops are much faster in Julia than in Matlab.

On Tuesday, November 25, 2014 2:26:39 PM UTC-6, Peter Simon wrote:

 You can find examples of both meshgrid and ndgrid implemented in 
 https://github.com/JuliaLang/julia/blob/master/examples/ndgrid.jl .
 However, you will find that generally meshgrid is not needed, as similar 
 functionality can be accomplished by broadcasting 
 http://docs.julialang.org/en/release-0.3/manual/arrays/?highlight=broadcast#broadcasting
  or 
 by use of comprehensions 
 http://docs.julialang.org/en/release-0.3/manual/arrays/?highlight=broadcast#comprehensions
 .

 --Peter

 On Tuesday, November 25, 2014 11:39:57 AM UTC-8, Pileas wrote:

 Hi brothers,

 I am practicing a little bit in Julia now, and I want to see how meshgrid 
 (if there is any) works. I found an example in Matlab (for I find it easier 
 to cope with and make it Julia compatible), but I don't know how to do the 
 meshgrid.

 Here is the example:

 --
 col = 20;
 m = 400;
 cx = -.6;
 cy = 0;
 l = 1.5;
 x = linspace(cx-l,cx + l,m);
 y = linspace(cy-l,cy + l,m);
 (X,Y) = ndgrid(x,y);
 Z = zeros(m);
 C = X + i * Y;

 for k = 1:col;
 Z = Z.^2+C;
 W = exp(-abs(Z));
 end

 colormap copper(256);
 pcolor(W);
 shading flat;
 axis(’square’,’equal’,’off’);
 -

 I would really appreciate if someone can give a working example in Julia 
 of the aforementioned.


 Best ...



[julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread Daniel Høegh
Here is my solution, there is one problem that i do not understand and hope 
another can explain. When col=20 W is filled with NaN + NaN*im but for col=10 
it work like matlab, I think it is because of overflow.
using PyPlot
col = 10;
m = 400;
cx = -.6;
cy = 0;
l = 1.5;
x = linspace(cx-l,cx + l,m);
y = linspace(cy-l,cy + l,m);
X = repmat(x,1,m)
Y = repmat(y,1,m)'
Z = zeros(m,m);
C = X + im * Y;
W = zeros(Z)
for k = 1:col;
Z = Z.*Z+C
W = exp(-abs(Z));
println(Z[100,100])
end


pcolor(W,cmap=ColorMap(copper))

By changing the calculation to happen with BigFloats it works. 
Z = zeros(BigFloat, m,m);
pcolor(float64(W),cmap=ColorMap(copper))

[julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread Steven G. Johnson
Note that you don't need to use meshgrid, repmat, or similar, because you 
can use broadcasting operations (e.g .+) to combine row and column vectors:

col = 20;
m = 400;
cx = -.6;
cy = 0;
l = 1.5;
x = linspace(cx-l,cx + l,m);
y = linspace(cy-l,cy + l,m);
Z = zeros(m,m);
C = x' .+ im * y;

for k = 1:col;
Z = Z.^2+C;
end
W = exp(-abs(Z));

pcolor(W, cmap=copper);
colorbar()
axis(equal)


(Note also that there are more efficient ways to do this in Julia because 
you aren't forced to rely on vectorized operations, which allocate lots of 
temporary arrays, in order to get good performance.)


Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread Phoebus Apollo
it does not understand pcolor, even when I load PyPlot. Why? Do we need to
load a different package?


2014-11-25 15:59 GMT-05:00 Steven G. Johnson stevenj@gmail.com:

 Note that you don't need to use meshgrid, repmat, or similar, because you
 can use broadcasting operations (e.g .+) to combine row and column vectors:

 col = 20;
 m = 400;
 cx = -.6;
 cy = 0;
 l = 1.5;
 x = linspace(cx-l,cx + l,m);
 y = linspace(cy-l,cy + l,m);
 Z = zeros(m,m);
 C = x' .+ im * y;

 for k = 1:col;
 Z = Z.^2+C;
 end
 W = exp(-abs(Z));

 pcolor(W, cmap=copper);
 colorbar()
 axis(equal)


 (Note also that there are more efficient ways to do this in Julia because
 you aren't forced to rely on vectorized operations, which allocate lots of
 temporary arrays, in order to get good performance.)



Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread Steven G. Johnson
On Tuesday, November 25, 2014 4:05:58 PM UTC-5, Pileas wrote:

 it does not understand pcolor, even when I load PyPlot. Why? Do we need to 
 load a different package?


No.  Maybe you don't have Matplotlib installed.  (I would generally 
recommend using the Anaconda Python distro, which will include everything 
you might need, including IPython for running IJulia.)


Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread Pileas
I get the following error:

/usr/lib/pymodules/python2.7/matplotlib/colorbar.py:581: RuntimeWarning: 
invalid value encountered in greater
  inrange = (ticks  -0.001)  (ticks  1.001)

And I have Anaconda installed.


Τη Τρίτη, 25 Νοεμβρίου 2014 4:59:22 μ.μ. UTC-5, ο χρήστης Steven G. Johnson 
έγραψε:

 On Tuesday, November 25, 2014 4:05:58 PM UTC-5, Pileas wrote:

 it does not understand pcolor, even when I load PyPlot. Why? Do we need 
 to load a different package?


 No.  Maybe you don't have Matplotlib installed.  (I would generally 
 recommend using the Anaconda Python distro, which will include everything 
 you might need, including IPython for running IJulia.)



Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread Steven G. Johnson
On Tuesday, November 25, 2014 9:26:31 PM UTC-5, Pileas wrote:

 I get the following error:

 /usr/lib/pymodules/python2.7/matplotlib/colorbar.py:581: RuntimeWarning: 
 invalid value encountered in greater
   inrange = (ticks  -0.001)  (ticks  1.001)

 And I have Anaconda installed.


Maybe, like the error says, you have an invalid value -- something in your 
array that is not a number, for example.

For example, try
 pcolor(rand(10,10))
which should work. 


Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread Steven G. Johnson
(Note that the example code for the Mandelbrot set above produces an array 
containing NaN values.  Maybe that doesn't work if you have an old version 
of Matplotlib.  Maybe try doing a conda update etc. to be sure you have a 
recent version?)


Re: [julia-users] Re: Meshgrid in Julia: a working example and possible alternatives

2014-11-25 Thread David Smith
My up-to-date version of Matplotlib won't plot NaNs either.

On Tuesday, November 25, 2014 10:22:22 PM UTC-6, Steven G. Johnson wrote:

 (Note that the example code for the Mandelbrot set above produces an array 
 containing NaN values.  Maybe that doesn't work if you have an old version 
 of Matplotlib.  Maybe try doing a conda update etc. to be sure you have a 
 recent version?)