{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualizing Multipore Zeolite Framework Classifications" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " Loading BokehJS ...\n", "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function(global) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " var force = true;\n", "\n", " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n", " window._bokeh_onload_callbacks = [];\n", " window._bokeh_is_loading = undefined;\n", " }\n", "\n", "\n", " \n", " if (typeof (window._bokeh_timeout) === \"undefined\" || force === true) {\n", " window._bokeh_timeout = Date.now() + 5000;\n", " window._bokeh_failed_load = false;\n", " }\n", "\n", " var NB_LOAD_WARNING = {'data': {'text/html':\n", " \"
\\n\"+\n", " \"

\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"

\\n\"+\n", " \"\\n\"+\n", " \"\\n\"+\n", " \"from bokeh.resources import INLINE\\n\"+\n", " \"output_notebook(resources=INLINE)\\n\"+\n", " \"\\n\"+\n", " \"
\"}};\n", "\n", " function display_loaded() {\n", " if (window.Bokeh !== undefined) {\n", " var el = document.getElementById(\"a082e93b-2310-4a66-a341-2a42d0a6f981\");\n", " el.textContent = \"BokehJS \" + Bokeh.version + \" successfully loaded.\";\n", " } else if (Date.now() < window._bokeh_timeout) {\n", " setTimeout(display_loaded, 100)\n", " }\n", " }\n", "\n", " function run_callbacks() {\n", " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", " delete window._bokeh_onload_callbacks\n", " console.info(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(js_urls, callback) {\n", " window._bokeh_onload_callbacks.push(callback);\n", " if (window._bokeh_is_loading > 0) {\n", " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls == null || js_urls.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " window._bokeh_is_loading = js_urls.length;\n", " for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " var s = document.createElement('script');\n", " s.src = url;\n", " s.async = false;\n", " s.onreadystatechange = s.onload = function() {\n", " window._bokeh_is_loading--;\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", " run_callbacks()\n", " }\n", " };\n", " s.onerror = function() {\n", " console.warn(\"failed to load library \" + url);\n", " };\n", " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " }\n", " };var element = document.getElementById(\"a082e93b-2310-4a66-a341-2a42d0a6f981\");\n", " if (element == null) {\n", " console.log(\"Bokeh: ERROR: autoload.js configured with elementid 'a082e93b-2310-4a66-a341-2a42d0a6f981' but no matching script tag was found. \")\n", " return false;\n", " }\n", "\n", " var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.5.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.5.min.js\"];\n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " \n", " function(Bokeh) {\n", " \n", " },\n", " \n", " function(Bokeh) {\n", " \n", " document.getElementById(\"a082e93b-2310-4a66-a341-2a42d0a6f981\").textContent = \"BokehJS is loading...\";\n", " },\n", " function(Bokeh) {\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.5.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.5.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.5.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.5.min.css\");\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " \n", " if ((window.Bokeh !== undefined) || (force === true)) {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i](window.Bokeh);\n", " }if (force === true) {\n", " display_loaded();\n", " }} else if (Date.now() < window._bokeh_timeout) {\n", " setTimeout(run_inline_js, 100);\n", " } else if (!window._bokeh_failed_load) {\n", " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", " window._bokeh_failed_load = true;\n", " } else if (force !== true) {\n", " var cell = $(document.getElementById(\"a082e93b-2310-4a66-a341-2a42d0a6f981\")).parents('.cell').data().cell;\n", " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", " }\n", "\n", " }\n", "\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(js_urls, function() {\n", " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(this));" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import math\n", "import pandas as pd\n", "pd.options.display.max_rows = 240\n", "\n", "from bokeh.io import output_notebook\n", "from bokeh.plotting import figure, show, output_file\n", "from bokeh.charts import Bar\n", "from bokeh.charts.attributes import cat\n", "from bokeh.models import HoverTool, ColumnDataSource, FixedTicker\n", "from bokeh.palettes import Category10, Set1, Spectral, Set3, Viridis\n", "\n", "output_notebook()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from zefram.utils import get_framework_data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df = get_framework_data()\n", "\n", "df.rename(columns={'lcd': 'Largest cavity dia.', 'pld': 'Pore limiting dia.',\n", " 'maxdsi': 'Max dia. of inc. sphere'}, inplace=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# prepare the data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def number_of_relevant_rings(rings):\n", " 'get the number of rings 6 < R < 13, +1 if there are any extra large rings'\n", "\n", " s = sorted(i for i in rings if (13 > i > 6))\n", " xl = sorted(i for i in rings if i > 12)\n", " lenxl = 0\n", " if len(xl) >= 1:\n", " lenxl = 1\n", " return len(s) + lenxl\n", "\n", "def ring_colors(rings):\n", " 'assign colors to specific ring sizes'\n", "\n", " colors = {7 + i: Viridis[6][i] for i in range(6)} \n", " s = sorted(i for i in rings if (13 > i > 6))\n", " out = [colors[r] for r in s]\n", " \n", " # add a grey color if there is an extra large ring\n", " if any(r > 12 for r in rings):\n", " out.append('#696969')\n", " \n", " if len(out) > 0:\n", " return out\n", "\n", "df.loc[:, 'no_rings'] = df.rings.apply(number_of_relevant_rings)\n", "df.loc[:, 'ring_colors'] = df.rings.apply(ring_colors)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot with circle fractions" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "from sklearn.utils.extmath import cartesian\n", " \n", "def show_plot_arcs(dataframe, width=750, height=300,radius=0.4, alpha=0.6, title=None, showit=True):\n", "\n", " df = dataframe.copy()\n", " \n", " ncols = 15\n", " nitems = df.shape[0]\n", "\n", " if nitems % ncols == 0:\n", " nrows = nitems / ncols\n", " else:\n", " nrows = nitems // ncols + 1\n", "\n", " xy = cartesian([np.arange(nrows), np.arange(ncols)])\n", "\n", " df.loc[:, 'x'] = xy[:nitems, 1]\n", " df.loc[:, 'y'] = xy[:nitems, 0]\n", "\n", " p = figure(title=title,\n", " x_range = (df.x.min() - 0.5, df.x.max() + 0.5),\n", " y_range = (df.y.max() + 0.5, df.y.min() - 0.5),\n", " plot_width=width, plot_height=height, tools='save',\n", " toolbar_location=\"above\")\n", "\n", " \n", " dmask = df['channel_dim'] > 1\n", " # empty circles\n", " x = df.loc[~dmask, 'x'].values\n", " y = df.loc[~dmask, 'y'].values\n", " p.circle(x, y, radius=radius, color='#ffffff', fill_alpha=1.0, line_color='#888888')\n", " \n", " # full circles\n", " mask1 = dmask & (df['no_rings'] == 1)\n", " x = df.loc[mask1, 'x'].values\n", " y = df.loc[mask1, 'y'].values\n", " \n", " c = list(list(zip(*df.loc[mask1, 'ring_colors'].values.tolist()))[0])\n", " p.circle(x, y, radius=radius, color=c, fill_alpha=alpha, line_color='#888888')\n", " \n", " # half circles/wedges\n", " mask2 = dmask & (df['no_rings'] == 2)\n", " x = df.loc[mask2, 'x'].values\n", " y = df.loc[mask2, 'y'].values\n", " c1, c2 = list(zip(*df.loc[mask2, 'ring_colors'].values.tolist()))\n", " p.wedge(x, y, radius=radius, start_angle=math.pi/4, end_angle=5*math.pi/4,\n", " color=list(c1), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=5*math.pi/4, end_angle=math.pi/4,\n", " color=list(c2), alpha=alpha, direction=\"anticlock\")\n", " \n", " # third circles/wedges\n", " mask3 = dmask & (df['no_rings'] == 3)\n", " x = df.loc[mask3, 'x'].values\n", " y = df.loc[mask3, 'y'].values\n", " c1, c2, c3 = list(zip(*df.loc[mask3, 'ring_colors'].values.tolist()))\n", " p.wedge(x, y, radius=radius, start_angle=math.pi/2, end_angle=7*math.pi/6,\n", " color=list(c1), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=7*math.pi/6, end_angle=11*math.pi/6,\n", " color=list(c2), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=11*math.pi/6, end_angle=math.pi/2,\n", " color=list(c3), alpha=alpha, direction=\"anticlock\")\n", " \n", " # outer line\n", " outer_colors = {'2d': Set1[5][4], '3d': Set1[5][0]}\n", "\n", " d2mask = df['channel_dim'] == 2\n", " x = df.loc[d2mask, 'x'].values\n", " y = df.loc[d2mask, 'y'].values\n", " p.circle(x, y, radius=radius + 0.02, color='#ffffff', fill_alpha=0.0,\n", " line_color=outer_colors['2d'], line_width=5.0, line_alpha=alpha)\n", "\n", " d3mask = df['channel_dim'] == 3\n", " x = df.loc[d3mask, 'x'].values\n", " y = df.loc[d3mask, 'y'].values\n", " p.circle(x, y, radius=radius + 0.02, color='#ffffff', fill_alpha=0.0,\n", " line_color=outer_colors['3d'], line_width=5.0, line_alpha=alpha)\n", " \n", " # legend\n", " maxx = df['x'].max()\n", " maxy = df['y'].max()\n", " p.circle([x + 5.5 for x in range(7)], [maxy] * 7,\n", " color=Viridis[6] + ['#696969'], radius=0.1, alpha=alpha)\n", " p.circle([12.5, 13.5], [maxy] * 2,\n", " color='#ffffff', radius=0.15, line_color=[outer_colors['2d'], outer_colors['3d']],\n", " line_width=5.0, line_alpha=alpha)\n", " p.text([x + 5.7 for x in range(9)], [maxy] * 9,\n", " text=['7', '8', '9', '10', '11', '12', 'XL', '2D', '3D'],\n", " text_alpha=0.7, text_align='left', text_baseline='middle')\n", "\n", " text_props = {\n", " \"text_font\": \"times\",\n", " \"text_font_style\": \"bold\",\n", " \"text_font_size\": \"13pt\",\n", " \"angle\": 0,\n", " \"color\": \"black\",\n", " \"text_alpha\": 0.7,\n", " \"text_align\": \"center\",\n", " \"text_baseline\": \"middle\"\n", " }\n", "\n", " p.text(x=df.x.values, y=df.y.values, text=df.code.values, **text_props)\n", " \n", " p.grid.grid_line_color = None\n", "\n", " p.axis[0].ticker.num_minor_ticks = 0\n", " p.axis[1].ticker.num_minor_ticks = 0\n", " p.axis.major_label_text_font_size = '0pt'\n", " p.axis.major_tick_line_color = None\n", "\n", " p.border_fill_color = 'white'\n", " p.outline_line_width = 0\n", " p.axis.visible = False\n", "\n", " if showit:\n", " show(p)\n", " else:\n", " return p" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_plot_arcs(df, width=900, height=900, radius=0.38, alpha=0.7)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Multipore zeolites" ] }, { "cell_type": "code", "execution_count": 60, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy as np\n", "from sklearn.utils.extmath import cartesian\n", " \n", "def has_multipores(rings):\n", "\n", " s = sorted(i for i in rings if (13 > i > 6))\n", " xl = sorted(i for i in rings if i > 12)\n", "\n", " if len(s) + len(xl) >= 2:\n", " return True\n", " else:\n", " return False\n", " \n", "def show_plot_arcs_multipore(dataframe, width=750, height=300, radius=0.4, alpha=0.6, title=None, showit=True):\n", "\n", " df = dataframe.copy()\n", " \n", " ncols = 15\n", " nitems = df.shape[0]\n", "\n", " if nitems % ncols == 0:\n", " nrows = nitems / ncols\n", " else:\n", " nrows = nitems // ncols + 1\n", "\n", " xy = cartesian([np.arange(nrows), np.arange(ncols)])\n", "\n", " df.loc[:, 'x'] = xy[:nitems, 1]\n", " df.loc[:, 'y'] = xy[:nitems, 0]\n", "\n", " p = figure(title=title,\n", " x_range = (df.x.min() - 0.5, df.x.max() + 0.5),\n", " y_range = (df.y.max() + 0.5, df.y.min() - 0.5),\n", " plot_width=width, plot_height=height, tools='save',\n", " toolbar_location=\"above\")\n", "\n", " \n", " mmask = (df['channel_dim'] > 1) & df.rings.apply(has_multipores)\n", " # empty circles\n", " x = df.loc[~mmask, 'x'].values\n", " y = df.loc[~mmask, 'y'].values\n", " p.circle(x, y, radius=radius, color='#ffffff', fill_alpha=1.0, line_color='#888888')\n", "\n", " # full circles special case or the IRY framework\n", " mask1 = (df['no_rings'] == 1) & mmask\n", " x = df.loc[mask1, 'x'].values\n", " y = df.loc[mask1, 'y'].values\n", " c = list(list(zip(*df.loc[mask1, 'ring_colors'].values.tolist()))[0])\n", " p.circle(x, y, radius=radius, color=c, fill_alpha=alpha, line_color='#888888')\n", " \n", " # half circles/wedges\n", " mask2 = mmask & (df['no_rings'] == 2)\n", " x = df.loc[mask2, 'x'].values\n", " y = df.loc[mask2, 'y'].values\n", " c1, c2 = list(zip(*df.loc[mask2, 'ring_colors'].values.tolist()))\n", " p.wedge(x, y, radius=radius, start_angle=math.pi/4, end_angle=5*math.pi/4,\n", " color=list(c1), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=5*math.pi/4, end_angle=math.pi/4,\n", " color=list(c2), alpha=alpha, direction=\"anticlock\")\n", " \n", " # third circles/wedges\n", " mask3 = mmask & (df['no_rings'] == 3)\n", " x = df.loc[mask3, 'x'].values\n", " y = df.loc[mask3, 'y'].values\n", " c1, c2, c3 = list(zip(*df.loc[mask3, 'ring_colors'].values.tolist()))\n", " p.wedge(x, y, radius=radius, start_angle=math.pi/2, end_angle=7*math.pi/6,\n", " color=list(c1), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=7*math.pi/6, end_angle=11*math.pi/6,\n", " color=list(c2), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=11*math.pi/6, end_angle=math.pi/2,\n", " color=list(c3), alpha=alpha, direction=\"anticlock\")\n", " \n", " # outer line\n", " outer_colors = {'2d': Set1[5][4], '3d': Set1[5][0]}\n", "\n", " d2mask = (df['channel_dim'] == 2) & mmask\n", " x = df.loc[d2mask, 'x'].values\n", " y = df.loc[d2mask, 'y'].values\n", " p.circle(x, y, radius=radius + 0.02, color='#ffffff', fill_alpha=0.0,\n", " line_color=outer_colors['2d'], line_width=5.0, line_alpha=alpha)\n", "\n", " d3mask = (df['channel_dim'] == 3) & mmask\n", " x = df.loc[d3mask, 'x'].values\n", " y = df.loc[d3mask, 'y'].values\n", " p.circle(x, y, radius=radius + 0.02, color='#ffffff', fill_alpha=0.0,\n", " line_color=outer_colors['3d'], line_width=5.0, line_alpha=alpha)\n", " \n", " # legend\n", " maxx = df['x'].max()\n", " maxy = df['y'].max()\n", " p.circle([x + 5.5 for x in range(7)], [maxy] * 7,\n", " color=Viridis[6] + ['#696969'], radius=0.1, alpha=alpha)\n", " p.circle([12.5, 13.5], [maxy] * 2,\n", " color='#ffffff', radius=0.15, line_color=[outer_colors['2d'], outer_colors['3d']],\n", " line_width=5.0, line_alpha=alpha)\n", " p.text([x + 5.7 for x in range(9)], [maxy] * 9,\n", " text=['7', '8', '9', '10', '11', '12', 'XL', '2D', '3D'],\n", " text_alpha=0.7, text_align='left', text_baseline='middle')\n", "\n", " text_props = {\n", " \"text_font\": \"times\",\n", " \"text_font_style\": \"bold\",\n", " \"text_font_size\": \"13pt\",\n", " \"angle\": 0,\n", " \"color\": \"black\",\n", " \"text_alpha\": 0.7,\n", " \"text_align\": \"center\",\n", " \"text_baseline\": \"middle\"\n", " }\n", "\n", " p.text(x=df.x.values, y=df.y.values, text=df.code.values, **text_props)\n", " \n", " p.grid.grid_line_color = None\n", "\n", " p.axis[0].ticker.num_minor_ticks = 0\n", " p.axis[1].ticker.num_minor_ticks = 0\n", " p.axis.major_label_text_font_size = '0pt'\n", " p.axis.major_tick_line_color = None\n", "\n", " p.border_fill_color = 'white'\n", " p.outline_line_width = 0\n", " p.axis.visible = False\n", "\n", " if showit:\n", " show(p)\n", " else:\n", " return p" ] }, { "cell_type": "code", "execution_count": 61, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_plot_arcs_multipore(df, width=900, height=900, radius=0.38, alpha=0.7)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def show_plot_arcs_multipore_only(dataframe, width=750, height=300, radius=0.4, alpha=0.6, title=None, showit=True):\n", "\n", " df = dataframe.copy()\n", " \n", " ncols = 9\n", " nitems = df.shape[0]\n", "\n", " if nitems % ncols == 0:\n", " nrows = nitems / ncols\n", " else:\n", " nrows = nitems // ncols + 1\n", "\n", " xy = cartesian([np.arange(nrows), np.arange(ncols)])\n", "\n", " df.loc[:, 'x'] = xy[:nitems, 1]\n", " df.loc[:, 'y'] = xy[:nitems, 0]\n", "\n", " p = figure(title=title,\n", " x_range = (df.x.min() - 0.5, df.x.max() + 0.5),\n", " y_range = (df.y.max() + 1.5, df.y.min() - 0.5),\n", " plot_width=width, plot_height=height, tools='save',\n", " toolbar_location=\"above\")\n", "\n", " # full circles special case or the IRY framework\n", " mask1 = (df['no_rings'] == 1)\n", " x = df.loc[mask1, 'x'].values\n", " y = df.loc[mask1, 'y'].values\n", " c = list(list(zip(*df.loc[mask1, 'ring_colors'].values.tolist()))[0])\n", " p.circle(x, y, radius=radius, color=c, fill_alpha=alpha, line_color='#888888')\n", " \n", " # half circles/wedges\n", " mask2 = (df['no_rings'] == 2)\n", " x = df.loc[mask2, 'x'].values\n", " y = df.loc[mask2, 'y'].values\n", " c1, c2 = list(zip(*df.loc[mask2, 'ring_colors'].values.tolist()))\n", " p.wedge(x, y, radius=radius, start_angle=math.pi/4, end_angle=5*math.pi/4,\n", " color=list(c1), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=5*math.pi/4, end_angle=math.pi/4,\n", " color=list(c2), alpha=alpha, direction=\"anticlock\")\n", " \n", " # third circles/wedges\n", " mask3 = (df['no_rings'] == 3)\n", " x = df.loc[mask3, 'x'].values\n", " y = df.loc[mask3, 'y'].values\n", " c1, c2, c3 = list(zip(*df.loc[mask3, 'ring_colors'].values.tolist()))\n", " p.wedge(x, y, radius=radius, start_angle=math.pi/2, end_angle=7*math.pi/6,\n", " color=list(c1), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=7*math.pi/6, end_angle=11*math.pi/6,\n", " color=list(c2), alpha=alpha, direction=\"anticlock\")\n", " p.wedge(x, y, radius=radius, start_angle=11*math.pi/6, end_angle=math.pi/2,\n", " color=list(c3), alpha=alpha, direction=\"anticlock\")\n", " \n", " # outer line\n", " outer_colors = {'2d': Set1[5][4], '3d': Set1[5][0]}\n", "\n", " #m23mask = (df['no_rings'] == 2) | (df['no_rings'] == 3)\n", " d2mask = (df['channel_dim'] == 2)# & m23mask\n", " x = df.loc[d2mask, 'x'].values\n", " y = df.loc[d2mask, 'y'].values\n", " p.circle(x, y, radius=radius + 0.03, color='#ffffff', fill_alpha=0.0,\n", " line_color=outer_colors['2d'], line_width=7.0, line_alpha=alpha)\n", "\n", " d3mask = (df['channel_dim'] == 3)# & m23mask\n", " x = df.loc[d3mask, 'x'].values\n", " y = df.loc[d3mask, 'y'].values\n", " p.circle(x, y, radius=radius + 0.03, color='#ffffff', fill_alpha=0.0,\n", " line_color=outer_colors['3d'], line_width=7.0, line_alpha=alpha)\n", " \n", " # legend\n", " maxx = df['x'].max()\n", " maxy = df['y'].max()\n", " p.circle([x for x in range(7)], [maxy + 1] * 7,\n", " color=Viridis[6] + ['#696969'], radius=0.1, alpha=alpha)\n", " p.circle([7.0, 8.0], [maxy + 1] * 2,\n", " color='#ffffff', radius=0.15, line_color=[outer_colors['2d'], outer_colors['3d']],\n", " line_width=5.0, line_alpha=alpha)\n", " p.text([x + 0.2 for x in range(9)], [maxy + 1] * 9,\n", " text=['7', '8', '9', '10', '11', '12', 'XL', '2D', '3D'],\n", " text_alpha=0.7, text_align='left', text_baseline='middle')\n", "\n", " text_props = {\n", " \"text_font\": \"times\",\n", " \"text_font_style\": \"bold\",\n", " \"text_font_size\": \"13pt\",\n", " \"angle\": 0,\n", " \"color\": \"black\",\n", " \"text_alpha\": 0.7,\n", " \"text_align\": \"center\",\n", " \"text_baseline\": \"middle\"\n", " }\n", "\n", " p.text(x=df.x.values, y=df.y.values, text=df.code.values, **text_props)\n", " \n", " p.grid.grid_line_color = None\n", "\n", " p.axis[0].ticker.num_minor_ticks = 0\n", " p.axis[1].ticker.num_minor_ticks = 0\n", " p.axis.major_label_text_font_size = '0pt'\n", " p.axis.major_tick_line_color = None\n", "\n", " p.border_fill_color = 'white'\n", " p.outline_line_width = 0\n", " p.axis.visible = False\n", "\n", " if showit:\n", " show(p)\n", " else:\n", " return p" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mask = (df['channel_dim'] > 1) & df.rings.apply(has_multipores)\n", "show_plot_arcs_multipore_only(df[mask], width=900, height=900, radius=0.38, alpha=0.7)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Bar charts" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def multid_bar_plot(data, sizes, title=None, showit=True, dropna=True):\n", " '''\n", " plot a bar chart for a given category\n", " \n", " Args:\n", " data (pd.DataFrame) :\n", " \n", " sizes: list of ring sizes e.g. [8, 10], [8, 10, 12]\n", "\n", " '''\n", "\n", " def in_list(rings, sizes):\n", " 'obtain the mask'\n", "\n", " if set(sizes).issubset(set(rings)) and max(rings) == max(sizes):\n", " return True\n", " else:\n", " return False\n", " \n", " ring_mask = df.rings.apply(in_list, sizes=sizes)\n", " mask = (df['channel_dim'] > 1) & ring_mask\n", " cols = ['code', 'Largest cavity dia.', 'Pore limiting dia.', 'Max dia. of inc. sphere']\n", " melted = pd.melt(data.loc[mask, cols].dropna().sort_values(by='Largest cavity dia.'),\n", " id_vars=['code'], value_vars=cols[1:])\n", "\n", " p = Bar(melted, label=cat('code', sort=False), values=\"value\", group=\"variable\",\n", " legend=\"top_left\", xlabel='Framework code', ylabel='Length [Angstrom]',\n", " plot_width=900, title=title, toolbar_location=\"above\")\n", " \n", " if showit:\n", " show(p)\n", " else:\n", " return p" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "multid_bar_plot(df, [8, 10], title='Multipore frameworks with 8 and 10 MR')" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "multid_bar_plot(df, [8, 12], title='Multipore frameworks with 8 and 12 MR')" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "multid_bar_plot(df, [10, 12], title='Multipore frameworks with 10 and 12 MR')" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "multid_bar_plot(df, [8, 10, 12], title='Multipore frameworks with 8, 10, 12 MR')" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.6.1 64bit [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]" }, { "module": "IPython", "version": "6.0.0" }, { "module": "OS", "version": "Linux 3.16.0 4 amd64 x86_64 with debian 8.8" }, { "module": "bokeh", "version": "0.12.5" }, { "module": "pandas", "version": "0.20.1" }, { "module": "numpy", "version": "1.12.1" }, { "module": "zefram", "version": "0.1.2" } ] }, "text/html": [ "
SoftwareVersion
Python3.6.1 64bit [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
IPython6.0.0
OSLinux 3.16.0 4 amd64 x86_64 with debian 8.8
bokeh0.12.5
pandas0.20.1
numpy1.12.1
zefram0.1.2
Tue May 23 22:29:32 2017 CEST
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.6.1 64bit [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] \\\\ \\hline\n", "IPython & 6.0.0 \\\\ \\hline\n", "OS & Linux 3.16.0 4 amd64 x86\\_64 with debian 8.8 \\\\ \\hline\n", "bokeh & 0.12.5 \\\\ \\hline\n", "pandas & 0.20.1 \\\\ \\hline\n", "numpy & 1.12.1 \\\\ \\hline\n", "zefram & 0.1.2 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Tue May 23 22:29:32 2017 CEST} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.6.1 64bit [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]\n", "IPython 6.0.0\n", "OS Linux 3.16.0 4 amd64 x86_64 with debian 8.8\n", "bokeh 0.12.5\n", "pandas 0.20.1\n", "numpy 1.12.1\n", "zefram 0.1.2\n", "Tue May 23 22:29:32 2017 CEST" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%version_information bokeh, pandas, numpy, zefram" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }