{
"metadata": {
"name": "",
"signature": "sha256:a2ed52f299c8adad5584759457d0e2af35a026f09568114b01453d9c5099ff67"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"MultiCanvas Tutorial"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Objective"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook will demonstrate some of the basic features of **MultiCanvas**, the canonical container class for **Canvas**. A good real-world utilization is in the notebook, [labeling nanogold](http://nbviewer.ipython.org/github/hugadams/pyparty/blob/master/examples/Notebooks/groups_of_labels.ipynb?create=1)."
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Environment Setup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Configure notebook style (see NBCONFIG.ipynb), add imports and paths. The **%run** magic used below **requires IPython 2.0 or higher.**"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%run NBCONFIG.ipynb"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "display_data",
"text": [
""
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Initialization (from list of canvases (*canvii*) )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's use *Canvas.random_circles()* to generate 10 canvases with a random number of circles between 25 and 75 and randomly ordered names.\n",
"\n",
"MultiCanvas must be initialized with a **names** and **canvii** instance; both must be equally-sized lists. We will show alternative constructors subsequently."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import random \n",
"from pyparty import MultiCanvas\n",
"\n",
"nameslist = [ 'test-%s' % i for i in range(10) ]\n",
"random.shuffle(nameslist)\n",
"\n",
"names, canvii = [], []\n",
"for i in range(10):\n",
" canvii.append( Canvas.random_circles(n=random.randint(25,75) ) )\n",
" \n",
"mc = MultiCanvas(names=nameslist, canvii=canvii)\n",
"mc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"text": [
"MultiCanvas (0x74b2470) 548: \n",
" test-3 - Canvas (0x4c9f290) : 512 X 512 : 45 particles\n",
" test-6 - Canvas (0x4ece230) : 512 X 512 : 71 particles\n",
" test-7 - Canvas (0x50c5470) : 512 X 512 : 54 particles\n",
" test-1 - Canvas (0x5248410) : 512 X 512 : 53 particles\n",
" test-5 - Canvas (0x53ab3b0) : 512 X 512 : 41 particles\n",
" test-0 - Canvas (0x5bc9d70) : 512 X 512 : 70 particles\n",
" test-8 - Canvas (0x5dd0290) : 512 X 512 : 67 particles\n",
" test-4 - Canvas (0x5f00cb0) : 512 X 512 : 27 particles\n",
" test-9 - Canvas (0x733dc50) : 512 X 512 : 65 particles\n",
" test-2 - Canvas (0x74b2170) : 512 X 512 : 55 particles"
]
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Sorting"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's sort this (by name). When sorting multicanvas, **do not use pythons sorted() function; used mc.sort()**"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mc.sort(inplace=True)\n",
"mc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"MultiCanvas (0x74b2470) 548: \n",
" test-0 - Canvas (0x5bc9d70) : 512 X 512 : 70 particles\n",
" test-1 - Canvas (0x5248410) : 512 X 512 : 53 particles\n",
" test-2 - Canvas (0x74b2170) : 512 X 512 : 55 particles\n",
" test-3 - Canvas (0x4c9f290) : 512 X 512 : 45 particles\n",
" test-4 - Canvas (0x5f00cb0) : 512 X 512 : 27 particles\n",
" test-5 - Canvas (0x53ab3b0) : 512 X 512 : 41 particles\n",
" test-6 - Canvas (0x4ece230) : 512 X 512 : 71 particles\n",
" test-7 - Canvas (0x50c5470) : 512 X 512 : 54 particles\n",
" test-8 - Canvas (0x5dd0290) : 512 X 512 : 67 particles\n",
" test-9 - Canvas (0x733dc50) : 512 X 512 : 65 particles"
]
}
],
"prompt_number": 3
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Indexing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Indexing is as you'd expect. Valid indicies include:\n",
" - Integer\n",
" - Integer slice\n",
" - eg [5:3], [3::] etc...\n",
" - Single name (string)\n",
" \n",
"A slice that returns multiple objects will return a MulitCanvas. A slice that returns a single element will return a Canvas. This is the same behavior as Python's list slicing."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print mc[4:7]\n",
"\n",
"NAME = mc.names[0]\n",
"mc[NAME].show(title='Showing Canvas: %s' % NAME);"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"MultiCanvas (0x74b27d0) 139: \n",
" test-4 - Canvas (0x5f00cb0) : 512 X 512 : 27 particles\n",
" test-5 - Canvas (0x53ab3b0) : 512 X 512 : 41 particles\n",
" test-6 - Canvas (0x4ece230) : 512 X 512 : 71 particles\n"
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Setting a deleting by item are also supported, **but only by single key**; the same as a python dictionary:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mc['test'] = Canvas.random_circles(n=20)\n",
"print '\"test\" found:', 'test' in mc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\"test\" found: True\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"del mc['test'] \n",
"print '\"test\" found:', 'test' in mc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\"test\" found: False\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Some other ported container method include:\n",
"- **insert**(name, canvas)\n",
"- **pop**(idx) "
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Plotting "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A major motivator for designing the multi-canvas was in to create **multiplots, stacked histograms and pie charts**. A non-trivial utilization of these is shown in the [labeling nanogold](http://nbviewer.ipython.org/github/hugadams/pyparty/blob/master/examples/Notebooks/groups_of_labels.ipynb?create=1) example. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**One important point about these plots:**** please pass optional arguments as keywords and not as a list of args**. To allow for passing *ax* as a positional argument, pyparty doesn't attempt to parse the other positional arguments. This may be fixed later, but for now, please only use keyword args (for example bins=50).\n",
"\n",
"Let me take only the first 4 samples from the multi canvas so that the plots do not get too cluttered."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mc_cut = mc[0:4]"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mc_cut.show(names=True)\n",
"mc_cut.patchshow(colors=False, figsize=(8,6), gcolor='red');"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**show() and patchshow()** wrap their respective Canvas methods, so any valid arguments (like colormaps, grids etc...) should just work. In addition, multicanvas show methods have the following additional keyword arguments:\n",
"\n",
"- names: bool (False)\n",
" - Show multicanvas names at top of plot\n",
" \n",
"- colors: bool (True):\n",
" - Map stored color to each particle in subplot.\n",
" \n",
"pyparty.splot arguments like column number and figsize (ncols, figsize) are valid. If a user does not specify the number of columns, *they will default to 4 and empty plots will be cutoff*.\n",
"\n",
"** If passing a pre-constructed axes/subplots to mc.show(), it must be as a keyword. As a positional, it will not work! (see below)**"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"axes = splot(2,3)\n",
"mc_cut.show(axes=axes, colors=False, cmap='gray');"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Histogram**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Besides any valid [matplotlib histogram](http://matplotlib.org/api/pyplot_api.html) keywords, the following additional options have been implemented:\n",
"\n",
"- **annotate:** (True)\n",
" - Add general legend, title, axis labels. \n",
" \n",
"- **attr:** (area)\n",
" - Particle attribute for data. (Also a pie chart keyword).\n",
" \n",
"- **xlim:** (None)\n",
" - Shortcut to set xlimits. If **xlim=auto**, absolute min and absolute max of data will be used. This crops data AND sets axis limits; to only change plot axes, use *axes.set_xlim()*.\n",
"\n",
"We see that the **annotate** option adds a legend, title and axis labels. The default attribute of the histogram is *area*, corresponding to the **attr** kwargs. All other valid [matplotlib histogram](http://matplotlib.org/api/pyplot_api.html) kwargs should work."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ax1, ax2 = splot(1,2)\n",
"\n",
"# Scientific notation on x-axis\n",
"ax1.ticklabel_format(axis='x', style='sci', scilimits=(0,1))\n",
"ax2.ticklabel_format(axis='x', style='sci', scilimits=(0,1))\n",
"\n",
"mc_cut.hist(ax1)\n",
"mc_cut.hist(ax2, annotate=False);"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Pie Chart**"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ax1, ax2 = splot(1,2)\n",
"mc_cut.pie(ax1)\n",
"mc_cut.pie(ax2, annotate=False);"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The default pie chart is an annotated (title, labels etc...) breakdown by *particle count* per canvas. Instead of the distribution by particle count, we can look at *area*, *eccentricity* or any descriptor that can be summed via the **attr** keyword. The two new options for pie chart are:\n",
"\n",
"- **autopct:** str or fcn or None\n",
" - Label of pie slices. Some built in short cuts include \"count\", \"percentage\", \"both\". Note results in no labels. \n",
"\n",
"- **usetex :** bool (True)\n",
" - Label of pie slcies use latex rendering. If matplotlib.rcparams usetex = True, then set this to True.\n",
" \n",
"- **metavar:** str or None\n",
" - Name to use in title when referring to attribute. If None, attr is used. \n",
" \n",
"Usetex should be set to whatever setting plt.rcParams is using. By default, usetex is False. If the rendering of the labels looks bizarre on the piechart, change this option. Autopct adds a few basic shortcuts for different styles of pie labels. In addition, any [matplotlib piechart](http://matplotlib.org/api/pyplot_api.html) kwarg should work. **For latex to properly render, ensure you have ghostscript and dvipng installed (apt-get compatible). Also, be careful when using axis labels of variables with underscores!**\n",
"\n",
"In the next example, we will show how to properly render latex tex."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from matplotlib import rc\n",
"rc('text', usetex=True)\n",
"ax1, ax2 = splot(1,2)\n",
"\n",
"piekwargs = {'attr':'equivalent_diameter', 'autopct':'count', \n",
" 'usetex':True, 'shadow':True, 'explode':(0,0,0,0.1)}\n",
"\n",
"mc_cut.pie(ax1, **piekwargs)\n",
"mc_cut.pie(ax2, metavar='Equivalent\\_Diameter', **piekwargs);"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the above example, notice that the underscore in the title is not a problem. This would be a problem if we had used usetex=True, since latex doesn't render underscores. (Easiest fix is just to do ax.set_title('new title'). You can also tell that the font and text weight are different when compared to the prior pie charts, in which usetex is True (set in NBCONFIG). **The difference are more pronounced when rendering math symbols.** Let me now turn it off:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"rc('text', usetex=False)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Transmuting"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Sometimes we'd like to output the MultiCanvas as a standard Python type, such as a dictionary with names as keys and canvii as values. Or maybe we don't want the whole canvas, we just need the particle area array or the binary image, or any other valid canvas attribute. **mc.transmute()** provides a general and simple method for this. One specifies merely two options:\n",
"\n",
"- as_type: tuple, dict, OrderedDict, None\n",
" - Output (name, value) as desired type. If None, a generator expression is returned.\n",
"- attr: str or None\n",
" - Any valid canvas attribute. If None, the entire canvas is returned as the *value* in (name, value) pairs. \n",
" \n",
"So, let's output a dictionary of names, areas, and a list of tuple pairs of names, grayimage."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"area_dict = mc.transmute(attr='area', as_type=dict)\n",
"tuple_imgs = mc.transmute(attr='grayimage', as_type=tuple)\n",
"\n",
"print type(area_dict), type(tuple_imgs)\n",
"\n",
"name, grayimg = tuple_imgs[0]\n",
"showim(grayimg, title='Showing ``%s\" from tuple transmute' % name);"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 14
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Alternate Constructors"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Currently, MultiCanvas implements two important constructors:\n",
"\n",
"- **MultiCanvas.from_labeled**(img, *names, pmanwkargs*)\n",
" - Takes a labeled image (see below) and creates a multicanvas which each names corresponding to one of the labels. Same arguments are valid for multi_masks().\n",
" - ignore: label to be regarded as background; defaults to 0.\n",
" - neighbors: connectivity for labeling; defaults to 4\n",
" - maximum: maximum labels allowed; default to 10 (may cause slow down if higiher)\n",
" - names: use these names instead of values of the labels.\n",
" - pmankwargs: label argument for particle manager such as pmin (min particle size to count)\n",
" \n",
" \n",
"- **MultiCanvas.from_canvas**(canvas, *names*)\n",
" - Takes a canvas and splits based on different ptype (circle, triangle etc...)\n",
" - names: use these instead of canvas ptypes.\n",
" - pmankwargs: label argument for particle manager such as pmin (min particle size to count)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**from_labeled(img, names, kwargs)** is shown in the related [labeling nanogold](http://nbviewer.ipython.org/github/hugadams/pyparty/blob/master/examples/Notebooks/groups_of_labels.ipynb?create=1) example in more detail. Here is a quick example in which we map the particles between red and blue based on the mean area, then read this into a MultiCanvas::"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def red_or_blue(p, cutoff=2500):\n",
" \"\"\" Color blue/red based on cutoff area size\"\"\"\n",
" p.color = 'r'\n",
" if p.area > cutoff:\n",
" p.color = 'blue'\n",
" return p\n",
"\n",
"c= mc[0]\n",
"c.pmap(red_or_blue, np.mean(c.area), inplace=True)\n",
"c.show();"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mc_colored = MultiCanvas.from_labeled(c.image, 'p-blue', 'p-red', ignore='white')\n",
"mc_colored"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"WARNING:pyparty.utils:3-Channel converted to 1-channel (gray).\n"
]
},
{
"output_type": "stream",
"stream": "stderr",
"text": [
"WARNING:pyparty.multi:Ignore set to None but was not found on image.\n"
]
},
{
"output_type": "stream",
"stream": "stderr",
"text": [
"WARNING:pyparty.multi:length : 2 names provided but 3 unique labels were found\n"
]
},
{
"output_type": "stream",
"stream": "stderr",
"text": [
"WARNING:pyparty.tools.manager:pmin < 10 may result in errors in some particle descriptors\n"
]
},
{
"output_type": "stream",
"stream": "stderr",
"text": [
"WARNING:pyparty.tools.manager:pmin < 10 may result in errors in some particle descriptors\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 16,
"text": [
"MultiCanvas (0x9dfe530) 37: \n",
" p-blue - Canvas (0x9e07650) : 512 X 512 : 10 particles\n",
" p-red - Canvas (0x9dfe830) : 512 X 512 : 27 particles"
]
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ax1, ax2 = splot(1,2)\n",
"kwargs={'attr':'area', 'colors':['blue', 'red']}\n",
"mc_colored.pie(ax1, **kwargs)\n",
"mc_colored.hist(ax2, bins=5, xlim='auto', **kwargs); "
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 17
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"**mc.from_canvas()**"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"c1 = Canvas.random_circles(n=10, pcolor='yellow')\n",
"c2 = Canvas.random_triangles(n=10, pcolor='red')\n",
"c3 = c1+ c2\n",
"c3.patchshow();"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print MultiCanvas.from_canvas(c3)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"MultiCanvas (0x8f7fd10) 20: \n",
" circle - Canvas (0xcdf6a10) : 512 X 512 : 10 particles\n",
" triangle - Canvas (0xd6656b0) : 512 X 512 : 10 particles\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the names parameter to reassign the names to the multicanvas. It's fairly flexible in that one can enter fewer or more than the number of names already on the multicanvas; it will let you know with a warning."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print MultiCanvas.from_canvas(c3, 'yellow-circle'), '\\n'\n",
"print MultiCanvas.from_canvas(c3, 'yellow-circle', 'red-triangle', 'unusedname')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"WARNING:pyparty.multi:length : 1 names provided but 2 unique labels were found\n"
]
},
{
"output_type": "stream",
"stream": "stderr",
"text": [
"WARNING:pyparty.multi:length : 3 names provided but 2 unique labels were found\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"MultiCanvas (0x9f8bb90) 20: \n",
" yellow-circle - Canvas (0x9dff230) : 512 X 512 : 10 particles\n",
" triangle - Canvas (0x9ecafb0) : 512 X 512 : 10 particles \n",
"\n",
"MultiCanvas (0x9f8b650) 20: \n",
" yellow-circle - Canvas (0x9f8bd10) : 512 X 512 : 10 particles\n",
" red-triangle - Canvas (0x9eca830) : 512 X 512 : 10 particles"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
}
],
"prompt_number": 20
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Colors"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Colors can be set to a particular name in the multicanvas via **mc.set_colors(colors, namecolor)**. These colors will persist through the various plots and are useful when *collapsing* a multicanvas (see below). These are stored in the **mc.mycolors** attribute.\n",
"\n",
"Not all names in the multicanvas need a color; if a custom color is not found, *the standard plotting color cycle is used.* Calling set_colors() should be done as:\n",
"\n",
"- **mc.set_colors('r','g'):** \n",
" - Set the first two colors in self.names to red and green, respectively\n",
"\n",
"- **mc.set_colors(singles='red', dimers=(0,0,1):**\n",
" - Set singles to red, dimers to blue. Key error if invalid name.\n",
" - Any valid matplotlib color argument is acceptable; **these are NOT rgb-converted internally by pyparty.**\n",
" \n",
"- **mc.set_colors():**\n",
" - Purge stored colors."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mc = MultiCanvas.from_canvas(c3)\n",
"mc.set_colors('gray', 'purple')\n",
"mc.set_names('cool-circle', 'swag-triangle') \n",
"print 'Names and Colors: %s' % mc.mycolors\n",
"\n",
"ax1, ax2 = splot(1,2)\n",
"\n",
"mc.hist(ax1, bins=10)\n",
"ax1.ticklabel_format(axis='x', style='sci', scilimits=(0,1))\n",
"mc.pie(ax2, attr='area');"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Names and Colors: {'circle': 'gray', 'cool-circle': 'gray', 'triangle': 'purple', 'swag-triangle': 'purple'}\n"
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 21
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Collapsing To Canvas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*mc.to_canvas()* changes MultiCanvas back into a Canvas. This is useful for operations that are easier to conduct in the multicanvas framework. For example, we showed how to change colors and names based on particle species.. By collapsing into a single canvas, we may preserve these changes with *mapcolors* and *mapnames*. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cout = mc.to_canvas(mapcolors=True, mapnames=True)\n",
"print cout, '\\n'\n",
"print \"Canvas ptypes:\", cout.ptypes\n",
"cout.patchshow();"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Canvas (0x90bc410):\n",
" background --> (512 X 512) : default\n",
" particles --> 20 particles : 2 types\n",
" xygrid[225] --> (15p X 15p) : (34.1 X 34.1) [pix/tile] \n",
"\n",
"Canvas ptypes: ('cool-circle', 'swag-triangle')\n"
]
},
{
"metadata": {},
"output_type": "display_data",
"svg": [
"\n",
"\n",
"\n",
"\n"
],
"text": [
""
]
}
],
"prompt_number": 22
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Most collapsing operations are achievalbe from the Canvas directly. We could have just added the two Canvii and mapped the colors and new particle types to the resultant Canvas directly.\n",
"\n",
"*Quick Note:* When merging canvii of different resolution, the resultant canvas will be of the largest resolution of the set."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
" \n",
"\n",
"\n",
"