[matplotlib-devel] trisurf plots with independent color data

2015-01-21 Thread Byron K. Boulton
I often have Electromagnetic surface current data which I use MATLAB's trisurf 
function to plot. Since the surfaces are 3-dimensional I need a trisurf 
plotting tool which lets me specify the color of each triangle/vertex. MATLAB's 
trisurf function allows me to do that by passing it an array of colors 
(http://www.mathworks.com/help/matlab/ref/trisurf.html) along with the arrays 
of X, Y, and Z coordinates of vertices. 

Matplotlib's plot_trisurf from mplot3d only seems to allow me to specify one 
constant color for the entire trisurf plot or to color the triangles according 
to the z-coordinates. Are there any plans to add this functionality to 
mplot3d's plot_trisurf? Does anyone here know how difficult it would be?

Byron Boulton


--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] trisurf plots with independent color data

2015-01-21 Thread Maximilian Albert
Hi Byron,

This is a bit of a workaround, but you can specify facecolors explicitly by
creating a triangulation of your surface explicitly and creating a
Poly3DCollection with these facecolors. I'm attaching an example below
which is a modified version of the plot_trisurf demo [1] in the matplotlib
documentation. It showcases both random colors and a smooth gradient (the
latter in the line that's commented out).

I would have thought that it should be possible to pass an argument like
"facecolors" to plot_trisurf directly, since the documentation [2] states
that "other arguments are passed on to Poly3DCollection". However, I
couldn't get this to work quickly. Maybe someone else knows how?

Best regards,
Max

[1] http://matplotlib.org/examples/mplot3d/trisurf3d_demo.html
[2] http://matplotlib.org/mpl_toolkits/mplot3d/api.html



from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np

from matplotlib.tri import Triangulation
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

n_angles = 36
n_radii = 8

# An array of radii
# Does not include radius r=0, this is to eliminate duplicate points
radii = np.linspace(0.125, 1.0, n_radii)

# An array of angles
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)

# Repeat all angles for each radius
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)

# Convert polar (radii, angles) coords to cartesian (x, y) coords
# (0, 0) is added here. There are no duplicate points in the (x, y) plane
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())

# Pringle surface
z = np.sin(-x*y)

tri = Triangulation(x, y)  # NOTE: This assumes that there is a nice
projection of the surface into the x/y-plane!
triangle_vertices = np.array([np.array([[x[T[0]], y[T[0]], z[T[0]]],
[x[T[1]], y[T[1]], z[T[1]]],
[x[T[2]], y[T[2]], z[T[2) for T
in tri.triangles])
midpoints = np.average(triangle_vertices, axis=1)

def find_color_for_point(pt):
x, y, z = pt
col = [(y+1)/2, (1-y)/2, 0]
return col

#facecolors = [find_color_for_point(pt) for pt in midpoints]  # smooth
gradient
facecolors = [np.random.random(3) for pt in midpoints]  # random colors

coll = Poly3DCollection(triangle_vertices, facecolors=facecolors,
edgecolors='black')

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.add_collection(coll)
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
ax.elev = 50

plt.show()
--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] trisurf plots with independent color data

2015-01-21 Thread Byron K. Boulton
Thanks. This looks like it might work for me. I got your example to work, but I 
still need to figure out how to apply it to my problem. In particular there is 
the note about your Triangulation line which says that we assume there is a 
nice projection of the surface into the x/y-plane. Is this just a requirement 
of the Triangulation function or of the Poly3Dcollection? My surfaces are 
typically enclosed bodies, but since they’re meshed for the Electromagnetic 
Simulation I already know the connectivity of the vertices. Also, in your 
example it appears that you define one color per triangle but the trisurf files 
I have consist of one color per vertex. Will I need to come up with my own 
function for defining facecolors based on the three color values associated 
with each of my triangles?

Byron Boulton

From: Maximilian Albert [mailto:[email protected]]
Sent: Wednesday, January 21, 2015 11:03 AM
To: Byron K. Boulton
Cc: [email protected]
Subject: Re: [matplotlib-devel] trisurf plots with independent color data

Hi Byron,

This is a bit of a workaround, but you can specify facecolors explicitly by 
creating a triangulation of your surface explicitly and creating a 
Poly3DCollection with these facecolors. I'm attaching an example below which is 
a modified version of the plot_trisurf demo [1] in the matplotlib 
documentation. It showcases both random colors and a smooth gradient (the 
latter in the line that's commented out).

I would have thought that it should be possible to pass an argument like 
"facecolors" to plot_trisurf directly, since the documentation [2] states that 
"other arguments are passed on to Poly3DCollection". However, I couldn't get 
this to work quickly. Maybe someone else knows how?

Best regards,
Max

[1] 
http://matplotlib.org/examples/mplot3d/trisurf3d_demo.html
[2] 
http://matplotlib.org/mpl_toolkits/mplot3d/api.html



from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np

from matplotlib.tri import Triangulation
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

n_angles = 36
n_radii = 8

# An array of radii
# Does not include radius r=0, this is to eliminate duplicate points
radii = np.linspace(0.125, 1.0, n_radii)

# An array of angles
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)

# Repeat all angles for each radius
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)

# Convert polar (radii, angles) coords to cartesian (x, y) coords
# (0, 0) is added here. There are no duplicate points in the (x, y) plane
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())

# Pringle surface
z = np.sin(-x*y)

tri = Triangulation(x, y)  # NOTE: This assumes that there is a nice projection 
of the surface into the x/y-plane!
triangle_vertices = np.array([np.array([[x[T[0]], y[T[0]], z[T[0]]],
[x[T[1]], y[T[1]], z[T[1]]],
[x[T[2]], y[T[2]], z[T[2) for T in 
tri.triangles])
midpoints = np.average(triangle_vertices, axis=1)

def find_color_for_point(pt):
x, y, z = pt
col = [(y+1)/2, (1-y)/2, 0]
return col

#facecolors = [find_color_for_point(pt) for pt in midpoints]  # smooth gradient
facecolors = [np.random.random(3) for pt in midpoints]  # random colors

coll = Poly3DCollection(triangle_vertices, facecolors=facecolors, 
edgecolors='black')

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.add_collection(coll)
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
ax.elev = 50

plt.show()

--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] trisurf plots with independent color data

2015-01-21 Thread Geoffroy Billotey
Hi,

You can also try to pass a *color* array of size ntri (number of triangles)
to the *set_array* method of the collection returned by *plot_trisurf*.

See for instance:
http://stackoverflow.com/questions/24218543/colouring-the-surface-of-a-sphere-with-a-set-of-scalar-values-in-matplotlib/24229480#24229480



2015-01-21 17:02 GMT+01:00 Maximilian Albert :

> Hi Byron,
>
> This is a bit of a workaround, but you can specify facecolors explicitly
> by creating a triangulation of your surface explicitly and creating a
> Poly3DCollection with these facecolors. I'm attaching an example below
> which is a modified version of the plot_trisurf demo [1] in the matplotlib
> documentation. It showcases both random colors and a smooth gradient (the
> latter in the line that's commented out).
>
> I would have thought that it should be possible to pass an argument like
> "facecolors" to plot_trisurf directly, since the documentation [2] states
> that "other arguments are passed on to Poly3DCollection". However, I
> couldn't get this to work quickly. Maybe someone else knows how?
>
> Best regards,
> Max
>
> [1] http://matplotlib.org/examples/mplot3d/trisurf3d_demo.html
> [2] http://matplotlib.org/mpl_toolkits/mplot3d/api.html
>
>
>
> from mpl_toolkits.mplot3d import Axes3D
> from matplotlib import cm
> import matplotlib.pyplot as plt
> import numpy as np
>
> from matplotlib.tri import Triangulation
> from mpl_toolkits.mplot3d.art3d import Poly3DCollection
>
> n_angles = 36
> n_radii = 8
>
> # An array of radii
> # Does not include radius r=0, this is to eliminate duplicate points
> radii = np.linspace(0.125, 1.0, n_radii)
>
> # An array of angles
> angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
>
> # Repeat all angles for each radius
> angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
>
> # Convert polar (radii, angles) coords to cartesian (x, y) coords
> # (0, 0) is added here. There are no duplicate points in the (x, y) plane
> x = np.append(0, (radii*np.cos(angles)).flatten())
> y = np.append(0, (radii*np.sin(angles)).flatten())
>
> # Pringle surface
> z = np.sin(-x*y)
>
> tri = Triangulation(x, y)  # NOTE: This assumes that there is a nice
> projection of the surface into the x/y-plane!
> triangle_vertices = np.array([np.array([[x[T[0]], y[T[0]], z[T[0]]],
> [x[T[1]], y[T[1]], z[T[1]]],
> [x[T[2]], y[T[2]], z[T[2) for
> T in tri.triangles])
> midpoints = np.average(triangle_vertices, axis=1)
>
> def find_color_for_point(pt):
> x, y, z = pt
> col = [(y+1)/2, (1-y)/2, 0]
> return col
>
> #facecolors = [find_color_for_point(pt) for pt in midpoints]  # smooth
> gradient
> facecolors = [np.random.random(3) for pt in midpoints]  # random colors
>
> coll = Poly3DCollection(triangle_vertices, facecolors=facecolors,
> edgecolors='black')
>
> fig = plt.figure()
> ax = fig.gca(projection='3d')
> ax.add_collection(coll)
> ax.set_xlim(-1, 1)
> ax.set_ylim(-1, 1)
> ax.set_zlim(-1, 1)
> ax.elev = 50
>
> plt.show()
>
>
>
> --
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> ___
> Matplotlib-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>
--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Matplotlib and Numfocus Fiscal Sponsorship Agreement (FSA)

2015-01-21 Thread Chris Barker
+1 -- sounds great!



On Tue, Jan 20, 2015 at 7:48 AM, Michael Droettboom  wrote:

>
>
>
>
>
>
>
>
> * Matplotlib is a widely used, well regarded, and powerful visualization
> library that has dominated the Python visualization stack for over a
> decade. However, to maintain that position, matplotlib must continue to
> evolve. Complementary or alternative libraries are appearing at an
> increasing rate, including browser-based plotting and GPU acceleration. To
> maintain its leadership position for the next decade, Matplotlib must
> interface with these alternatives while simultaneously expanding its
> capabilities and becoming easier to use and learn. Matplotlib’s large
> existing user base (greater than 50,000) means that new developments need
> to be carefully balanced with maintaining existing interfaces.  With the
> large user and code base comes a significant maintenance and user-support
> burden.  These responsibilities currently account for a majority of the
> core-developer time spent on matplotlib and has resulted in both the code
> base and community being in a healthier state than ever before. Even 6
> years ago there was no automated testing to speak of and the number of
> contributors continues to soar on github. However, this effort is, for the
> most part, done on a volunteer basis in the nights and weekends of the core
> developers.  To go beyond this maintenance level—to make step-change
> improvements for the benefit of matplotlib’s users—will require funding for
> full-time developers. Inspired and encouraged by the example of IPython, we
> would like to begin the process of fundraising. Managing funding on the
> needed scale is a complex and time-consuming process.  Thankfully,
> NumFOCUS, a 501(c)3 charity organisation co-founded by John Hunter, offers
> a fiscal sponsorship agreement to minimize the administrative and legal
> burden on open source projects. We would like to enlist NumFOCUS as our
> agents in all legal and financial matters, including banking, accepting
> donations as a non-profit, payroll, and access to legal counsel.  As part
> of the agreement, NumFOCUS would charge a percentage of all funds raised to
> cover their costs.  The full text of the agreement is attached. To comply
> with the legal and accounting requirements of a non-profit, matplotlib
> needs to form an administrative body to interact with NumFOCUS and direct
> the disbursement of any funds.  The proposed initial members of the body,
> are myself (Mike Droettboom), Eric Firing, Phil Elson, and Thomas Caswell,
> with Thomas acting as the point of contact with NumFOCUS. In practice,
> signing an FSA will have very little impact on the matplotlib project
> itself - it will still be BSD-licensed and community-driven as it has
> always been, and the only motivation for doing this is to give us an
> opportunity to apply for funding to do more work on matplotlib. We'd like
> to canvas the community's opinion on the matter, but to put a concrete
> timeline on the discussion, we would like to propose signing an FSA with
> NumFOCUS in 3 weeks (Feb 10th 2015) unless there is a major community
> discomfort with us doing so. Cheers, Michael Droettboom *
>
> --
> Michael Droettboom
> Science Software Branch
> Space Telescope Science Institute
> http://www.droettboom.com
>
>
>
> --
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> ___
> Matplotlib-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

[email protected]
--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Matplotlib and Numfocus Fiscal Sponsorship Agreement (FSA)

2015-01-21 Thread Nicolas P. Rougier

+1. Great news.

Nicolas.

> On 21 Jan 2015, at 20:22, Chris Barker  wrote:
> 
> +1 -- sounds great!
> 
> 
> 
> On Tue, Jan 20, 2015 at 7:48 AM, Michael Droettboom  wrote:
> Matplotlib
>   is a widely used, well regarded, and powerful visualization
>   library that has dominated the Python visualization stack for
>   over a decade. However, to maintain that position, matplotlib
>   must continue to evolve. Complementary or alternative
>   libraries are appearing at an increasing rate, including
>   browser-based plotting and GPU acceleration. To maintain its
>   leadership position for the next decade, Matplotlib must
>   interface with these alternatives while simultaneously
>   expanding its capabilities and becoming easier to use and
>   learn.
> 
> 
> Matplotlib’s
>   large existing user base (greater than 50,000) means that new
>   developments need to be carefully balanced with maintaining
>   existing interfaces.  With the large user and code base comes
>   a significant maintenance and user-support burden.  These
>   responsibilities currently account for a majority of the
>   core-developer time spent on matplotlib and has resulted in
>   both the code base and community being in a healthier state
>   than ever before. Even 6 years ago there was no automated
>   testing to speak of and the number of contributors continues
>   to soar on github. However, this effort is, for the most part,
>   done on a volunteer basis in the nights and weekends of the
>   core developers.  To go beyond this maintenance level—to make
>   step-change improvements for the benefit of matplotlib’s
>   users—will require funding for full-time developers. Inspired
>   and encouraged by the example of IPython, we would like to
>   begin the process of fundraising.
> 
> 
> Managing
>   funding on the needed scale is a complex and time-consuming
>   process.  Thankfully, NumFOCUS, a 501(c)3 charity organisation
>   co-founded by John Hunter, offers a fiscal sponsorship
>   agreement to minimize the administrative and legal burden on
>   open source projects. We would like to enlist NumFOCUS as our
>   agents in all legal and financial matters, including banking,
>   accepting donations as a non-profit, payroll, and access to
>   legal counsel.  As part of the agreement, NumFOCUS would
>   charge a percentage of all funds raised to cover their costs.
>The full text of the agreement is attached.
> 
> 
> To
>   comply with the legal and accounting requirements of a
>   non-profit, matplotlib needs to form an administrative body to
>   interact with NumFOCUS and direct the disbursement of any
>   funds.  The proposed initial members of the body, are myself
>   (Mike Droettboom), Eric Firing, Phil Elson, and Thomas
>   Caswell, with Thomas acting as the point of contact with
>   NumFOCUS.
> 
> 
> In
>   practice, signing an FSA will have very little impact on the
>   matplotlib project itself - it will still be BSD-licensed and
>   community-driven as it has always been, and the only
>   motivation for doing this is to give us an opportunity to
>   apply for funding to do more work on matplotlib. We'd like to
>   canvas the community's opinion on the matter, but to put a
>   concrete timeline on the discussion, we would like to propose
>   signing an FSA with NumFOCUS in 3 weeks (Feb 10th 2015) unless
>   there is a major community discomfort with us doing so. 
> 
> 
> 
> 
> 
> 
>   Cheers,
> 
> 
>   Michael Droettboom
> 
> 
> 
> 
> 
> -- 
> Michael Droettboom
> Science Software Branch
> Space Telescope Science Institute
> 
> 
> http://www.droettboom.com
> 
> --
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> ___
> Matplotlib-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
> 
> 
> 
> 
> -- 
> 
> Christopher Barker, Ph.D.
> Oceanographer
> 
> Emergency Response Division
> NOAA/NOS/OR&R(206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115   (206) 526-6317   main reception
> 
> [email protected]
> --