|
From: Hackstein <new...@gm...> - 2013-04-26 11:15:10
|
Thanks, Ryan, this is (amost) exactly what I was looking for. Now, I get the markers and their colors right, but I still have two problems:
The markers have a black edges, that I cannot get rid of. I've tried
rect = Rectangle(..., ec=None)
and also
col.set=edgecolor(None)
and 'None', respectively, both with no effect whatsoever.
The second problem is, that I cannot get the colorbar to work.
I tried
sc = ax.add_collection(col)
plt.colorbar(sc)
and
plt.colobar(col)
both do not work.
Any Ideas how to fix those two issues?
Thanks,
-Hackstein
> Message: 4
> Date: Thu, 25 Apr 2013 19:44:23 -0400
> From: Ryan Nelson <rne...@gm...>
> Subject: Re: [Matplotlib-users] Individual custom markers and colorbar
> To: mat...@li...
> Message-ID: <517...@gm...>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hackstein,
>
> Unfortunately, I'm not sure of an 'elegant' way to do what your asking
> with a single call to scatter. Others may know a better way. However,
> you can use rectangle patches and patch collections. (Requires a bit
> more code than scatter but is ultimately more flexible.)
>
> I think the example below does what you need, but with random numbers.
>
> Hope it helps a little.
>
> Ryan
>
> #######################
> import numpy as np
> import matplotlib.pyplot as plt
> from matplotlib.patches import Rectangle
> from matplotlib.collections import PatchCollection
>
> n = 100
>
> # Get your xy data points, which are the centers of the rectangles.
> xy = np.random.rand(n,2)
>
> # Set a fixed height
> height = 0.02
> # The variable widths of the rectangles
> widths = np.random.rand(n)*0.1
>
> # Get a color map and color values (normalized between 0 and 1)
> cmap = plt.cm.jet
> colors = np.random.rand(n)
>
> rects = []
> for p, w, c in zip(xy, widths, colors):
> xpos = p[0] - w/2 # The x position will be half the width from the
> center
> ypos = p[1] - height/2 # same for the y position, but with height
> rect = Rectangle( (xpos, ypos), w, height ) # Create a rectangle
> rects.append(rect) # Add the rectangle patch to our list
>
> # Create a collection from the rectangles
> col = PatchCollection(rects)
> # set the alpha for all rectangles
> col.set_alpha(0.3)
> # Set the colors using the colormap
> col.set_facecolor( cmap(colors) )
>
> # Make a figure and add the collection to the axis.
> ax = plt.subplot(111)
> ax.add_collection(col)
> plt.show()
>
> ###############################
>
>
> On 4/24/2013 5:35 PM, Hackstein wrote:
>>
>> Hi all,
>>
>> I am trying to get a scatter plot using a colormap. Additionally, I
>> need to define every marker for every data point individually -- each
>> being a rectangle with fixed height but varying width as a function of
>> the y-value. X and y being the data coordinates, z being a number to
>> be color coded with the colormap.
>>
>> Ideally, I would like to create a list of width and height values for
>> each data point and tell the scatter plot to use those.
>>
>> So far I got colormapped data with custom markers (simplified):
>>
>> [code]
>>
>> import numpy as np
>>
>> import matplotlib.pyplot as plt
>>
>> from pylab import *
>>
>> x = y = [1,2,3,4,5]
>>
>> z = [2,4,6,8,10]
>>
>> colors = cm.gnuplot2
>>
>> verts_vec = list(zip([-10.,10.,10.,-10.],[-5.,-5.,5.,5.]))
>>
>> fig = plt.figure(1, figsize=(14.40, 9.00))
>>
>> ax = fig.add_subplot(1,1,1)
>>
>> sc = ax.scatter(x, y, c=np.asarray(z), marker=None, edgecolor='None',
>> verts=verts_vec, cmap=colors, alpha=1.)
>>
>> plt.colorbar(sc, orientation='horizontal')
>>
>> plt.savefig('test.png', dpi=200)
>>
>> plt.close(1)
>>
>> [/code]
>>
>> But I need to define a marker size for each point, and I also need to
>> do that in axis scale values, not in points.
>>
>> I imagine giving verts a list of N*2 tuples instead of 2 tuples, N
>> being len(x), to define N individual markers.
>>
>> But when doing that I get the error that vertices.ndim==2.
>>
>> A less elegant way would be to plot every data point in an individual
>> scatter plot function, using a for-loop iterating over all data
>> points. Then, however, I see no way to apply a colormap and colorbar.
>>
>> What is the best way to accomplish that then?
>>
>> Thanks,
>>
>> -Hackstein
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Try New Relic Now & We'll Send You this Cool Shirt
>> New Relic is the only SaaS-based application performance monitoring service
>> that delivers powerful full stack analytics. Optimize and monitor your
>> browser, app, & servers with just a few lines of code. Try New Relic
>> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
> ------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
>
> ------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
> End of Matplotlib-users Digest, Vol 83, Issue 23
> ************************************************
|
|
From: Francesco M. <fra...@gm...> - 2013-04-26 12:07:22
|
Il giorno 26/apr/2013 13:16, "Hackstein" <new...@gm...> ha
scritto:
>
> Thanks, Ryan, this is (amost) exactly what I was looking for. Now, I get
the markers and their colors right, but I still have two problems:
> The markers have a black edges, that I cannot get rid of. I've tried
>
> rect = Rectangle(..., ec=None)
>
> and also
>
> col.set=edgecolor(None)
I think that you have to use the string 'none' instead of None type. The
latter is used to use the default value for the variable (in you case
black).
cheers
Francesco
>
> and 'None', respectively, both with no effect whatsoever.
>
> The second problem is, that I cannot get the colorbar to work.
> I tried
>
> sc = ax.add_collection(col)
> plt.colorbar(sc)
>
> and
>
> plt.colobar(col)
>
> both do not work.
> Any Ideas how to fix those two issues?
>
> Thanks,
>
> -Hackstein
>
>
> > Message: 4
> > Date: Thu, 25 Apr 2013 19:44:23 -0400
> > From: Ryan Nelson <rne...@gm...>
> > Subject: Re: [Matplotlib-users] Individual custom markers and colorbar
> > To: mat...@li...
> > Message-ID: <517...@gm...>
> > Content-Type: text/plain; charset="iso-8859-1"
> >
> > Hackstein,
> >
> > Unfortunately, I'm not sure of an 'elegant' way to do what your asking
> > with a single call to scatter. Others may know a better way. However,
> > you can use rectangle patches and patch collections. (Requires a bit
> > more code than scatter but is ultimately more flexible.)
> >
> > I think the example below does what you need, but with random numbers.
> >
> > Hope it helps a little.
> >
> > Ryan
> >
> > #######################
> > import numpy as np
> > import matplotlib.pyplot as plt
> > from matplotlib.patches import Rectangle
> > from matplotlib.collections import PatchCollection
> >
> > n = 100
> >
> > # Get your xy data points, which are the centers of the rectangles.
> > xy = np.random.rand(n,2)
> >
> > # Set a fixed height
> > height = 0.02
> > # The variable widths of the rectangles
> > widths = np.random.rand(n)*0.1
> >
> > # Get a color map and color values (normalized between 0 and 1)
> > cmap = plt.cm.jet
> > colors = np.random.rand(n)
> >
> > rects = []
> > for p, w, c in zip(xy, widths, colors):
> > xpos = p[0] - w/2 # The x position will be half the width from the
> > center
> > ypos = p[1] - height/2 # same for the y position, but with height
> > rect = Rectangle( (xpos, ypos), w, height ) # Create a rectangle
> > rects.append(rect) # Add the rectangle patch to our list
> >
> > # Create a collection from the rectangles
> > col = PatchCollection(rects)
> > # set the alpha for all rectangles
> > col.set_alpha(0.3)
> > # Set the colors using the colormap
> > col.set_facecolor( cmap(colors) )
> >
> > # Make a figure and add the collection to the axis.
> > ax = plt.subplot(111)
> > ax.add_collection(col)
> > plt.show()
> >
> > ###############################
> >
> >
> > On 4/24/2013 5:35 PM, Hackstein wrote:
> >>
> >> Hi all,
> >>
> >> I am trying to get a scatter plot using a colormap. Additionally, I
> >> need to define every marker for every data point individually -- each
> >> being a rectangle with fixed height but varying width as a function of
> >> the y-value. X and y being the data coordinates, z being a number to
> >> be color coded with the colormap.
> >>
> >> Ideally, I would like to create a list of width and height values for
> >> each data point and tell the scatter plot to use those.
> >>
> >> So far I got colormapped data with custom markers (simplified):
> >>
> >> [code]
> >>
> >> import numpy as np
> >>
> >> import matplotlib.pyplot as plt
> >>
> >> from pylab import *
> >>
> >> x = y = [1,2,3,4,5]
> >>
> >> z = [2,4,6,8,10]
> >>
> >> colors = cm.gnuplot2
> >>
> >> verts_vec = list(zip([-10.,10.,10.,-10.],[-5.,-5.,5.,5.]))
> >>
> >> fig = plt.figure(1, figsize=(14.40, 9.00))
> >>
> >> ax = fig.add_subplot(1,1,1)
> >>
> >> sc = ax.scatter(x, y, c=np.asarray(z), marker=None, edgecolor='None',
> >> verts=verts_vec, cmap=colors, alpha=1.)
> >>
> >> plt.colorbar(sc, orientation='horizontal')
> >>
> >> plt.savefig('test.png', dpi=200)
> >>
> >> plt.close(1)
> >>
> >> [/code]
> >>
> >> But I need to define a marker size for each point, and I also need to
> >> do that in axis scale values, not in points.
> >>
> >> I imagine giving verts a list of N*2 tuples instead of 2 tuples, N
> >> being len(x), to define N individual markers.
> >>
> >> But when doing that I get the error that vertices.ndim==2.
> >>
> >> A less elegant way would be to plot every data point in an individual
> >> scatter plot function, using a for-loop iterating over all data
> >> points. Then, however, I see no way to apply a colormap and colorbar.
> >>
> >> What is the best way to accomplish that then?
> >>
> >> Thanks,
> >>
> >> -Hackstein
> >>
> >>
> >>
> >>
------------------------------------------------------------------------------
> >> Try New Relic Now & We'll Send You this Cool Shirt
> >> New Relic is the only SaaS-based application performance monitoring
service
> >> that delivers powerful full stack analytics. Optimize and monitor your
> >> browser, app, & servers with just a few lines of code. Try New Relic
> >> and get this awesome Nerd Life shirt!
http://p.sf.net/sfu/newrelic_d2d_apr
> >>
> >>
> >> _______________________________________________
> >> Matplotlib-users mailing list
> >> Mat...@li...
> >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> >
> > ------------------------------
> >
> >
------------------------------------------------------------------------------
> > Try New Relic Now & We'll Send You this Cool Shirt
> > New Relic is the only SaaS-based application performance monitoring
service
> > that delivers powerful full stack analytics. Optimize and monitor your
> > browser, app, & servers with just a few lines of code. Try New Relic
> > and get this awesome Nerd Life shirt!
http://p.sf.net/sfu/newrelic_d2d_apr
> >
> > ------------------------------
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> >
> > End of Matplotlib-users Digest, Vol 83, Issue 23
> > ************************************************
>
>
------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring
service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
|
|
From: Hackstein <new...@gm...> - 2013-04-26 12:19:06
|
Thanks, Francesco, but I already tried for both and that doesn't work either.
Cheers,
Am 26.04.2013 um 14:07 schrieb Francesco Montesano <fra...@gm...>:
>
> Il giorno 26/apr/2013 13:16, "Hackstein" <new...@gm...> ha scritto:
> >
> > Thanks, Ryan, this is (amost) exactly what I was looking for. Now, I get the markers and their colors right, but I still have two problems:
> > The markers have a black edges, that I cannot get rid of. I've tried
> >
> > rect = Rectangle(..., ec=None)
> >
> > and also
> >
> > col.set=edgecolor(None)
>
> I think that you have to use the string 'none' instead of None type. The latter is used to use the default value for the variable (in you case black).
>
> cheers
> Francesco
> >
> > and 'None', respectively, both with no effect whatsoever.
> >
> > The second problem is, that I cannot get the colorbar to work.
> > I tried
> >
> > sc = ax.add_collection(col)
> > plt.colorbar(sc)
> >
> > and
> >
> > plt.colobar(col)
> >
> > both do not work.
> > Any Ideas how to fix those two issues?
> >
> > Thanks,
> >
> > -Hackstein
> >
> >
> > > Message: 4
> > > Date: Thu, 25 Apr 2013 19:44:23 -0400
> > > From: Ryan Nelson <rne...@gm...>
> > > Subject: Re: [Matplotlib-users] Individual custom markers and colorbar
> > > To: mat...@li...
> > > Message-ID: <517...@gm...>
> > > Content-Type: text/plain; charset="iso-8859-1"
> > >
> > > Hackstein,
> > >
> > > Unfortunately, I'm not sure of an 'elegant' way to do what your asking
> > > with a single call to scatter. Others may know a better way. However,
> > > you can use rectangle patches and patch collections. (Requires a bit
> > > more code than scatter but is ultimately more flexible.)
> > >
> > > I think the example below does what you need, but with random numbers.
> > >
> > > Hope it helps a little.
> > >
> > > Ryan
> > >
> > > #######################
> > > import numpy as np
> > > import matplotlib.pyplot as plt
> > > from matplotlib.patches import Rectangle
> > > from matplotlib.collections import PatchCollection
> > >
> > > n = 100
> > >
> > > # Get your xy data points, which are the centers of the rectangles.
> > > xy = np.random.rand(n,2)
> > >
> > > # Set a fixed height
> > > height = 0.02
> > > # The variable widths of the rectangles
> > > widths = np.random.rand(n)*0.1
> > >
> > > # Get a color map and color values (normalized between 0 and 1)
> > > cmap = plt.cm.jet
> > > colors = np.random.rand(n)
> > >
> > > rects = []
> > > for p, w, c in zip(xy, widths, colors):
> > > xpos = p[0] - w/2 # The x position will be half the width from the
> > > center
> > > ypos = p[1] - height/2 # same for the y position, but with height
> > > rect = Rectangle( (xpos, ypos), w, height ) # Create a rectangle
> > > rects.append(rect) # Add the rectangle patch to our list
> > >
> > > # Create a collection from the rectangles
> > > col = PatchCollection(rects)
> > > # set the alpha for all rectangles
> > > col.set_alpha(0.3)
> > > # Set the colors using the colormap
> > > col.set_facecolor( cmap(colors) )
> > >
> > > # Make a figure and add the collection to the axis.
> > > ax = plt.subplot(111)
> > > ax.add_collection(col)
> > > plt.show()
> > >
> > > ###############################
> > >
> > >
> > > On 4/24/2013 5:35 PM, Hackstein wrote:
> > >>
> > >> Hi all,
> > >>
> > >> I am trying to get a scatter plot using a colormap. Additionally, I
> > >> need to define every marker for every data point individually -- each
> > >> being a rectangle with fixed height but varying width as a function of
> > >> the y-value. X and y being the data coordinates, z being a number to
> > >> be color coded with the colormap.
> > >>
> > >> Ideally, I would like to create a list of width and height values for
> > >> each data point and tell the scatter plot to use those.
> > >>
> > >> So far I got colormapped data with custom markers (simplified):
> > >>
> > >> [code]
> > >>
> > >> import numpy as np
> > >>
> > >> import matplotlib.pyplot as plt
> > >>
> > >> from pylab import *
> > >>
> > >> x = y = [1,2,3,4,5]
> > >>
> > >> z = [2,4,6,8,10]
> > >>
> > >> colors = cm.gnuplot2
> > >>
> > >> verts_vec = list(zip([-10.,10.,10.,-10.],[-5.,-5.,5.,5.]))
> > >>
> > >> fig = plt.figure(1, figsize=(14.40, 9.00))
> > >>
> > >> ax = fig.add_subplot(1,1,1)
> > >>
> > >> sc = ax.scatter(x, y, c=np.asarray(z), marker=None, edgecolor='None',
> > >> verts=verts_vec, cmap=colors, alpha=1.)
> > >>
> > >> plt.colorbar(sc, orientation='horizontal')
> > >>
> > >> plt.savefig('test.png', dpi=200)
> > >>
> > >> plt.close(1)
> > >>
> > >> [/code]
> > >>
> > >> But I need to define a marker size for each point, and I also need to
> > >> do that in axis scale values, not in points.
> > >>
> > >> I imagine giving verts a list of N*2 tuples instead of 2 tuples, N
> > >> being len(x), to define N individual markers.
> > >>
> > >> But when doing that I get the error that vertices.ndim==2.
> > >>
> > >> A less elegant way would be to plot every data point in an individual
> > >> scatter plot function, using a for-loop iterating over all data
> > >> points. Then, however, I see no way to apply a colormap and colorbar.
> > >>
> > >> What is the best way to accomplish that then?
> > >>
> > >> Thanks,
> > >>
> > >> -Hackstein
> > >>
> > >>
> > >>
> > >> ------------------------------------------------------------------------------
> > >> Try New Relic Now & We'll Send You this Cool Shirt
> > >> New Relic is the only SaaS-based application performance monitoring service
> > >> that delivers powerful full stack analytics. Optimize and monitor your
> > >> browser, app, & servers with just a few lines of code. Try New Relic
> > >> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
> > >>
> > >>
> > >> _______________________________________________
> > >> Matplotlib-users mailing list
> > >> Mat...@li...
> > >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> > >
> > > -------------- next part --------------
> > > An HTML attachment was scrubbed...
> > >
> > > ------------------------------
> > >
> > > ------------------------------------------------------------------------------
> > > Try New Relic Now & We'll Send You this Cool Shirt
> > > New Relic is the only SaaS-based application performance monitoring service
> > > that delivers powerful full stack analytics. Optimize and monitor your
> > > browser, app, & servers with just a few lines of code. Try New Relic
> > > and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
> > >
> > > ------------------------------
> > >
> > > _______________________________________________
> > > Matplotlib-users mailing list
> > > Mat...@li...
> > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> > >
> > >
> > > End of Matplotlib-users Digest, Vol 83, Issue 23
> > > ************************************************
> >
> > ------------------------------------------------------------------------------
> > Try New Relic Now & We'll Send You this Cool Shirt
> > New Relic is the only SaaS-based application performance monitoring service
> > that delivers powerful full stack analytics. Optimize and monitor your
> > browser, app, & servers with just a few lines of code. Try New Relic
> > and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
|
|
From: Ryan N. <rne...@gm...> - 2013-04-26 12:30:52
|
Hackstein,
Francesco's suggestion works for me.
col.set_edgecolor( 'none' )
You can also set the linewidth to be 0.
col.set_linewidth( 0 )
Colorbars in these cases can be more painful than you might like. You
need to make a mappable object and pass that into a figure.colorbar
call. Rather than try to explain it in detail, I've just pasted a
modified version of my first script that should do what you need.
Glad we're getting closer.
Ryan
########################
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
n = 100
# Get your xy data points, which are the centers of the rectangles.
xy = np.random.rand(n,2)
# Set a fixed height
height = 0.02
# The variable widths of the rectangles
widths = np.random.rand(n)*0.1
# Get a color map and make some colors
cmap = plt.cm.hsv
colors = np.random.rand(n)*10.
# Make a normalized array of colors
colors_norm = colors/colors.max()
# Here's where you have to make a ScalarMappable with the colormap
mappable = plt.cm.ScalarMappable(cmap=cmap)
# Give it your non-normalized color data
mappable.set_array(colors)
rects = []
for p, w in zip(xy, widths):
xpos = p[0] - w/2 # The x position will be half the width from the
center
ypos = p[1] - height/2 # same for the y position, but with height
rect = Rectangle( (xpos, ypos), w, height ) # Create a rectangle
rects.append(rect) # Add the rectangle patch to our list
# Create a collection from the rectangles
col = PatchCollection(rects)
# set the alpha for all rectangles
col.set_alpha(0.3)
# Set the colors using the colormap
col.set_facecolor( cmap(colors_norm) )
# No lines
col.set_linewidth( 0 )
#col.set_edgecolor( 'none' )
# Make a figure and add the collection to the axis.
fig = plt.figure()
ax = fig.add_subplot(111)
ax.add_collection(col)
# Add your ScalarMappable to a figure colorbar
fig.colorbar(mappable)
plt.show()
########################
On 4/26/2013 7:15 AM, Hackstein wrote:
> Thanks, Ryan, this is (amost) exactly what I was looking for. Now, I get the markers and their colors right, but I still have two problems:
> The markers have a black edges, that I cannot get rid of. I've tried
>
> rect = Rectangle(..., ec=None)
>
> and also
>
> col.set=edgecolor(None)
>
> and 'None', respectively, both with no effect whatsoever.
>
> The second problem is, that I cannot get the colorbar to work.
> I tried
>
> sc = ax.add_collection(col)
> plt.colorbar(sc)
>
> and
>
> plt.colobar(col)
>
> both do not work.
> Any Ideas how to fix those two issues?
>
> Thanks,
>
> -Hackstein
>
>
>> Message: 4
>> Date: Thu, 25 Apr 2013 19:44:23 -0400
>> From: Ryan Nelson <rne...@gm...>
>> Subject: Re: [Matplotlib-users] Individual custom markers and colorbar
>> To: mat...@li...
>> Message-ID: <517...@gm...>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> Hackstein,
>>
>> Unfortunately, I'm not sure of an 'elegant' way to do what your asking
>> with a single call to scatter. Others may know a better way. However,
>> you can use rectangle patches and patch collections. (Requires a bit
>> more code than scatter but is ultimately more flexible.)
>>
>> I think the example below does what you need, but with random numbers.
>>
>> Hope it helps a little.
>>
>> Ryan
>>
>> #######################
>> import numpy as np
>> import matplotlib.pyplot as plt
>> from matplotlib.patches import Rectangle
>> from matplotlib.collections import PatchCollection
>>
>> n = 100
>>
>> # Get your xy data points, which are the centers of the rectangles.
>> xy = np.random.rand(n,2)
>>
>> # Set a fixed height
>> height = 0.02
>> # The variable widths of the rectangles
>> widths = np.random.rand(n)*0.1
>>
>> # Get a color map and color values (normalized between 0 and 1)
>> cmap = plt.cm.jet
>> colors = np.random.rand(n)
>>
>> rects = []
>> for p, w, c in zip(xy, widths, colors):
>> xpos = p[0] - w/2 # The x position will be half the width from the
>> center
>> ypos = p[1] - height/2 # same for the y position, but with height
>> rect = Rectangle( (xpos, ypos), w, height ) # Create a rectangle
>> rects.append(rect) # Add the rectangle patch to our list
>>
>> # Create a collection from the rectangles
>> col = PatchCollection(rects)
>> # set the alpha for all rectangles
>> col.set_alpha(0.3)
>> # Set the colors using the colormap
>> col.set_facecolor( cmap(colors) )
>>
>> # Make a figure and add the collection to the axis.
>> ax = plt.subplot(111)
>> ax.add_collection(col)
>> plt.show()
>>
>> ###############################
>>
>>
>> On 4/24/2013 5:35 PM, Hackstein wrote:
>>> Hi all,
>>>
>>> I am trying to get a scatter plot using a colormap. Additionally, I
>>> need to define every marker for every data point individually -- each
>>> being a rectangle with fixed height but varying width as a function of
>>> the y-value. X and y being the data coordinates, z being a number to
>>> be color coded with the colormap.
>>>
>>> Ideally, I would like to create a list of width and height values for
>>> each data point and tell the scatter plot to use those.
>>>
>>> So far I got colormapped data with custom markers (simplified):
>>>
>>> [code]
>>>
>>> import numpy as np
>>>
>>> import matplotlib.pyplot as plt
>>>
>>> from pylab import *
>>>
>>> x = y = [1,2,3,4,5]
>>>
>>> z = [2,4,6,8,10]
>>>
>>> colors = cm.gnuplot2
>>>
>>> verts_vec = list(zip([-10.,10.,10.,-10.],[-5.,-5.,5.,5.]))
>>>
>>> fig = plt.figure(1, figsize=(14.40, 9.00))
>>>
>>> ax = fig.add_subplot(1,1,1)
>>>
>>> sc = ax.scatter(x, y, c=np.asarray(z), marker=None, edgecolor='None',
>>> verts=verts_vec, cmap=colors, alpha=1.)
>>>
>>> plt.colorbar(sc, orientation='horizontal')
>>>
>>> plt.savefig('test.png', dpi=200)
>>>
>>> plt.close(1)
>>>
>>> [/code]
>>>
>>> But I need to define a marker size for each point, and I also need to
>>> do that in axis scale values, not in points.
>>>
>>> I imagine giving verts a list of N*2 tuples instead of 2 tuples, N
>>> being len(x), to define N individual markers.
>>>
>>> But when doing that I get the error that vertices.ndim==2.
>>>
>>> A less elegant way would be to plot every data point in an individual
>>> scatter plot function, using a for-loop iterating over all data
>>> points. Then, however, I see no way to apply a colormap and colorbar.
>>>
>>> What is the best way to accomplish that then?
>>>
>>> Thanks,
>>>
>>> -Hackstein
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Try New Relic Now & We'll Send You this Cool Shirt
>>> New Relic is the only SaaS-based application performance monitoring service
>>> that delivers powerful full stack analytics. Optimize and monitor your
>>> browser, app, & servers with just a few lines of code. Try New Relic
>>> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
>>>
>>>
>>> _______________________________________________
>>> Matplotlib-users mailing list
>>> Mat...@li...
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>>
>> ------------------------------
>>
>> ------------------------------------------------------------------------------
>> Try New Relic Now & We'll Send You this Cool Shirt
>> New Relic is the only SaaS-based application performance monitoring service
>> that delivers powerful full stack analytics. Optimize and monitor your
>> browser, app, & servers with just a few lines of code. Try New Relic
>> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
>>
>> ------------------------------
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>> End of Matplotlib-users Digest, Vol 83, Issue 23
>> ************************************************
> ------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
|
|
From: Sterling S. <sm...@fu...> - 2013-04-26 15:31:14
|
Notwithstanding these probably work (I haven't tried), my gut reaction would have been to color the edges the same as the face, although I don't know if you can give set_edgecolor the same cmap(colors_norm) argument. -Sterling On Apr 26, 2013, at 5:30AM, Ryan Nelson wrote: > Hackstein, > > Francesco's suggestion works for me. > col.set_edgecolor( 'none' ) > > You can also set the linewidth to be 0. > col.set_linewidth( 0 ) |
|
From: Brendan B. <bre...@br...> - 2013-04-26 17:56:35
|
On 2013-04-26 08:31, Sterling Smith wrote:
> Notwithstanding these probably work (I haven't tried), my gut
reaction would have been to color the edges the same as the face,
although I don't know if you can give set_edgecolor the same
cmap(colors_norm) argument.
I think you can set the edgecolor equal to the string 'face' to make
it use the facecolor.
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
|
|
From: Hackstein <new...@gm...> - 2013-04-26 15:39:56
|
Ryan, thank you very much, it works and it's exaclty how I needed it to look like! Cheers, |