{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/emperor/pulls/comments/87701953","pull_request_review_id":8306032,"id":87701953,"diff_hunk":"@@ -0,0 +1,337 @@\n+import matplotlib.pyplot as plt\n+import numpy as np\n+import seaborn as sns\n+\n+\n+def plot_3x3(ordination, offset, mapping, field, colors, null_kw=None,\n+             focus_kw=None):\n+    \"\"\"Construct a 3 x 3 plot of PC combinations\n+\n+    Where X is a PCn / PCm plot, _ is a blank spot, and L is the legend.\n+\n+    Offset defines the starting offset for the rows. If zero, the layout\n+    is:\n+\n+    PC1v2 PC1v3 PC1v4 BLANK\n+    PC2v3 PC2v4 PC2v5 Legend\n+    PC3v4 PC3v5 PC3v6 BLANK\n+\n+    Parameters\n+    ----------\n+    ordination : OrdinationResults\n+        An OrdinationResults object\n+    offset : int\n+        A starting offset\n+    mapping : DataFrame\n+        The covariate information for the samples.\n+    field : str\n+        The field within the mapping file to use for coloring.\n+    colors : dict, str\n+        If a dict, it is expected to provide a mapping of category value to\n+        a color; entries not in the mapping will be considered \"null\". If a\n+        str, the value is interpreted as the name of a color map and assumes\n+        a gradient is to be painted.\n+    null_kw : dict, optional\n+        Parameters to use for plotting and painting null or unknown values.\n+    focus_kw : dict, optional\n+        Parameters to use for plotting and painting values which are not\n+        null and in the field of interest.\n+    \"\"\"\n+    # setup defaults if not provided\n+    if null_kw is None:\n+        null_kw = {}\n+    if focus_kw is None:\n+        focus_kw = {}\n+\n+    # resolve if this is discrete or continous\n+    if isinstance(colors, str):\n+        plot = _two_dimensional_gradient\n+        legend = _legend_gradient\n+    else:\n+        plot = _two_dimensional_discrete\n+        legend = _legend_discrete\n+\n+    # full page, with square plots\n+    fig, grid = plt.subplots(3, 4, sharex=False, sharey=False,\n+                             figsize=(24, 16))\n+    grid[0, 3].grid(False)\n+    grid[0, 3].set_axis_off()\n+    grid[2, 3].grid(False)\n+    grid[2, 3].set_axis_off()\n+\n+    for row in range(3):\n+        # y_pc is the axis in the ordination to put on the y-axis\n+        y_pc = row + offset\n+\n+        # the y-axis is consistent across a row so only label the\n+        # first column\n+        row_ax = grid[row, 0]\n+        row_ax.set_ylabel(_pcoa_label(y_pc, ordination), fontsize=14)\n+\n+        for col in range(3):\n+            # x_pc is the axis in the ordination to put on the x-axis\n+            x_pc = row + col + offset + 1\n+\n+            # fetch the specific subplot, and plot\n+            ax = grid[row, col]\n+            ax.set_xlabel(_pcoa_label(x_pc, ordination), fontsize=14)\n+            plot(ax, field, mapping, ordination, x_pc, y_pc, colors, null_kw,\n+                 focus_kw)\n+\n+    # establish the legend on the right side\n+    legend(grid[1, 3], field, mapping, ordination, colors, null_kw)\n+\n+    return (fig, grid)\n+\n+\n+def _pcoa_label(dim, ordination):\n+    \"\"\"Helper method to make a PCoA label\"\"\"\n+    fmt = 'PC%d (%0.2f%%)'\n+    return fmt % (dim + 1, ordination.proportion_explained[dim] * 100)\n+\n+\n+def _two_dimensional_gradient(ax, field, mapping, ordination, xaxis, yaxis,\n+                              colormap, null_kw, focus_kw):\n+    \"\"\"Plot two axes\n+\n+    Parameters\n+    ----------\n+    ax : AxesSubplot\n+        A subplot to plot into\n+    field : str\n+        A metadata field in the mapping to plot.\n+    mapping : pd.DataFrame\n+        The metadata about the samples.\n+    ordination : skbio.OrdinationResults\n+        The ordination object.\n+    xaxis : integer\n+        An axis to plot from the ordination.\n+    yaxis : iteger\n+        An axis to plot from the ordination.\n+    colormap : str\n+        The colormap to use.\n+    null_kw : dict\n+        Additional arguments to the scatter plot for the samples in the\n+        background.\n+    focus_kw : dict\n+        Additional arguments to the scatter plot for the samples in focus.\n+    \"\"\"\n+    mapping = mapping.loc[ordination.samples.index]\n+    field_values = mapping[~mapping[field].isnull()][field]\n+\n+    nonfield_samples = set(mapping.index) - set(field_values.index)\n+\n+    # discretize our color gradient, and determine which bin (i.e., color)\n+    # a given value is associated with\n+    bins = np.arange(field_values.min(),\n+                     field_values.max(),\n+                     field_values.max() / 256)\n+\n+    order = np.digitize(field_values, bins=bins, right=True)\n+    colors = np.array(sns.color_palette(colormap, n_colors=len(bins) + 1))\n+\n+    # obtain the full vector of positions for each axis\n+    x_full = ordination.samples[xaxis]\n+    y_full = ordination.samples[yaxis]\n+\n+    # plot nulls\n+    x = x_full.loc[nonfield_samples]\n+    y = y_full.loc[nonfield_samples]\n+    ax.scatter(x, y, **null_kw)\n+\n+    # plot samples of interest\n+    x = x_full.loc[field_values.index].values\n+    y = y_full.loc[field_values.index].values\n+    ax.scatter(x, y, color=colors[order], **focus_kw)\n+\n+    # finalize\n+    ax.set_xlim(x_full.min() - 0.01, x_full.max() + 0.01)\n+    ax.set_ylim(y_full.min() - 0.01, y_full.max() + 0.01)\n+    ax.grid(False)\n+    ax.set_yticklabels([])\n+    ax.set_xticklabels([])\n+\n+\n+def _two_dimensional_discrete(ax, field, mapping, ordination, xaxis, yaxis,\n+                              colors, null_kw, focus_kw):\n+    \"\"\"Plot two axes\n+\n+    Parameters\n+    ----------\n+    ax : AxesSubplot\n+        A subplot to plot into\n+    field : str\n+        A metadata field in the mapping to plot.\n+    mapping : pd.DataFrame\n+        The metadata about the samples.\n+    ordination : skbio.OrdinationResults\n+        The ordination object.\n+    xaxis : integer\n+        An axis to plot from the ordination.\n+    yaxis : iteger\n+        An axis to plot from the ordination.\n+    colors : dict\n+        A mapping of a metadata value to a color. A category not present\n+        in the mapping is assumed to be \"null.\"\n+    null_kw : dict\n+        Additional arguments to the scatter plot for the samples in the\n+        background.\n+    focus_kw : dict\n+        Additional arguments to the scatter plot for the samples in focus.\n+    \"\"\"\n+    mapping = mapping.loc[ordination.samples.index]\n+    field_values = mapping[mapping[field].isin(set(colors))][field]\n+\n+    nonfield_samples = set(mapping.index) - set(field_values.index)\n+\n+    # obtain the full vector of positions for each axis\n+    x_full = ordination.samples[xaxis]\n+    y_full = ordination.samples[yaxis]\n+\n+    # plot nulls\n+    x = x_full.loc[nonfield_samples]\n+    y = y_full.loc[nonfield_samples]\n+    ax.scatter(x, y, **null_kw)\n+\n+    # plot samples of interest\n+    for value in field_values.unique():\n+        value_index = field_values[field_values == value].index\n+\n+        x = x_full.loc[value_index].values\n+        y = y_full.loc[value_index].values\n+        ax.scatter(x, y, color=colors.get(value), **focus_kw)\n+\n+    # finalize\n+    ax.set_xlim(x_full.min() - 0.01, x_full.max() + 0.01)\n+    ax.set_ylim(y_full.min() - 0.01, y_full.max() + 0.01)","path":"emperor/flat_plots.py","position":206,"original_position":206,"commit_id":"6d2855d9cbfbc1947329566ffa31e3af8f977322","original_commit_id":"6d2855d9cbfbc1947329566ffa31e3af8f977322","user":{"login":"wasade","id":474290,"avatar_url":"https://avatars.githubusercontent.com/u/474290?v=3","gravatar_id":"","url":"https://api.github.com/users/wasade","html_url":"https://github.com/wasade","followers_url":"https://api.github.com/users/wasade/followers","following_url":"https://api.github.com/users/wasade/following{/other_user}","gists_url":"https://api.github.com/users/wasade/gists{/gist_id}","starred_url":"https://api.github.com/users/wasade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wasade/subscriptions","organizations_url":"https://api.github.com/users/wasade/orgs","repos_url":"https://api.github.com/users/wasade/repos","events_url":"https://api.github.com/users/wasade/events{/privacy}","received_events_url":"https://api.github.com/users/wasade/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-11-12T22:53:58Z","updated_at":"2016-11-12T22:53:59Z","html_url":"https://github.com/biocore/emperor/pull/554#discussion_r87701953","pull_request_url":"https://api.github.com/repos/biocore/emperor/pulls/554","_links":{"self":{"href":"https://api.github.com/repos/biocore/emperor/pulls/comments/87701953"},"html":{"href":"https://github.com/biocore/emperor/pull/554#discussion_r87701953"},"pull_request":{"href":"https://api.github.com/repos/biocore/emperor/pulls/554"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/emperor/pulls/554","id":93423075,"html_url":"https://github.com/biocore/emperor/pull/554","diff_url":"https://github.com/biocore/emperor/pull/554.diff","patch_url":"https://github.com/biocore/emperor/pull/554.patch","issue_url":"https://api.github.com/repos/biocore/emperor/issues/554","number":554,"state":"open","locked":false,"title":"2d plotting","user":{"login":"wasade","id":474290,"avatar_url":"https://avatars.githubusercontent.com/u/474290?v=3","gravatar_id":"","url":"https://api.github.com/users/wasade","html_url":"https://github.com/wasade","followers_url":"https://api.github.com/users/wasade/followers","following_url":"https://api.github.com/users/wasade/following{/other_user}","gists_url":"https://api.github.com/users/wasade/gists{/gist_id}","starred_url":"https://api.github.com/users/wasade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wasade/subscriptions","organizations_url":"https://api.github.com/users/wasade/orgs","repos_url":"https://api.github.com/users/wasade/repos","events_url":"https://api.github.com/users/wasade/events{/privacy}","received_events_url":"https://api.github.com/users/wasade/received_events","type":"User","site_admin":false},"body":"@ElDeveloper, 2D plots with a notebook example. ","created_at":"2016-11-12T01:41:40Z","updated_at":"2016-11-12T22:53:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9755252c10e4a6382af5bc9f5146616f24b3d360","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/biocore/emperor/pulls/554/commits","review_comments_url":"https://api.github.com/repos/biocore/emperor/pulls/554/comments","review_comment_url":"https://api.github.com/repos/biocore/emperor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/emperor/issues/554/comments","statuses_url":"https://api.github.com/repos/biocore/emperor/statuses/6d2855d9cbfbc1947329566ffa31e3af8f977322","head":{"label":"wasade:2dplots","ref":"2dplots","sha":"6d2855d9cbfbc1947329566ffa31e3af8f977322","user":{"login":"wasade","id":474290,"avatar_url":"https://avatars.githubusercontent.com/u/474290?v=3","gravatar_id":"","url":"https://api.github.com/users/wasade","html_url":"https://github.com/wasade","followers_url":"https://api.github.com/users/wasade/followers","following_url":"https://api.github.com/users/wasade/following{/other_user}","gists_url":"https://api.github.com/users/wasade/gists{/gist_id}","starred_url":"https://api.github.com/users/wasade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wasade/subscriptions","organizations_url":"https://api.github.com/users/wasade/orgs","repos_url":"https://api.github.com/users/wasade/repos","events_url":"https://api.github.com/users/wasade/events{/privacy}","received_events_url":"https://api.github.com/users/wasade/received_events","type":"User","site_admin":false},"repo":{"id":22968246,"name":"emperor","full_name":"wasade/emperor","owner":{"login":"wasade","id":474290,"avatar_url":"https://avatars.githubusercontent.com/u/474290?v=3","gravatar_id":"","url":"https://api.github.com/users/wasade","html_url":"https://github.com/wasade","followers_url":"https://api.github.com/users/wasade/followers","following_url":"https://api.github.com/users/wasade/following{/other_user}","gists_url":"https://api.github.com/users/wasade/gists{/gist_id}","starred_url":"https://api.github.com/users/wasade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wasade/subscriptions","organizations_url":"https://api.github.com/users/wasade/orgs","repos_url":"https://api.github.com/users/wasade/repos","events_url":"https://api.github.com/users/wasade/events{/privacy}","received_events_url":"https://api.github.com/users/wasade/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wasade/emperor","description":"Emperor a tool for the analysis and visualization of large microbial ecology datasets","fork":true,"url":"https://api.github.com/repos/wasade/emperor","forks_url":"https://api.github.com/repos/wasade/emperor/forks","keys_url":"https://api.github.com/repos/wasade/emperor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wasade/emperor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wasade/emperor/teams","hooks_url":"https://api.github.com/repos/wasade/emperor/hooks","issue_events_url":"https://api.github.com/repos/wasade/emperor/issues/events{/number}","events_url":"https://api.github.com/repos/wasade/emperor/events","assignees_url":"https://api.github.com/repos/wasade/emperor/assignees{/user}","branches_url":"https://api.github.com/repos/wasade/emperor/branches{/branch}","tags_url":"https://api.github.com/repos/wasade/emperor/tags","blobs_url":"https://api.github.com/repos/wasade/emperor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wasade/emperor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wasade/emperor/git/refs{/sha}","trees_url":"https://api.github.com/repos/wasade/emperor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wasade/emperor/statuses/{sha}","languages_url":"https://api.github.com/repos/wasade/emperor/languages","stargazers_url":"https://api.github.com/repos/wasade/emperor/stargazers","contributors_url":"https://api.github.com/repos/wasade/emperor/contributors","subscribers_url":"https://api.github.com/repos/wasade/emperor/subscribers","subscription_url":"https://api.github.com/repos/wasade/emperor/subscription","commits_url":"https://api.github.com/repos/wasade/emperor/commits{/sha}","git_commits_url":"https://api.github.com/repos/wasade/emperor/git/commits{/sha}","comments_url":"https://api.github.com/repos/wasade/emperor/comments{/number}","issue_comment_url":"https://api.github.com/repos/wasade/emperor/issues/comments{/number}","contents_url":"https://api.github.com/repos/wasade/emperor/contents/{+path}","compare_url":"https://api.github.com/repos/wasade/emperor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wasade/emperor/merges","archive_url":"https://api.github.com/repos/wasade/emperor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wasade/emperor/downloads","issues_url":"https://api.github.com/repos/wasade/emperor/issues{/number}","pulls_url":"https://api.github.com/repos/wasade/emperor/pulls{/number}","milestones_url":"https://api.github.com/repos/wasade/emperor/milestones{/number}","notifications_url":"https://api.github.com/repos/wasade/emperor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wasade/emperor/labels{/name}","releases_url":"https://api.github.com/repos/wasade/emperor/releases{/id}","deployments_url":"https://api.github.com/repos/wasade/emperor/deployments","created_at":"2014-08-14T20:51:34Z","updated_at":"2015-03-24T02:06:32Z","pushed_at":"2016-11-12T20:09:23Z","git_url":"git://github.com/wasade/emperor.git","ssh_url":"git@github.com:wasade/emperor.git","clone_url":"https://github.com/wasade/emperor.git","svn_url":"https://github.com/wasade/emperor","homepage":"http://emperor.colorado.edu","size":30032,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"biocore:new-api","ref":"new-api","sha":"ee267cce03e653f871a50249ca9c41e9d9c4f4f5","user":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"repo":{"id":7758329,"name":"emperor","full_name":"biocore/emperor","owner":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biocore/emperor","description":"Emperor a tool for the analysis and visualization of large microbial ecology datasets","fork":false,"url":"https://api.github.com/repos/biocore/emperor","forks_url":"https://api.github.com/repos/biocore/emperor/forks","keys_url":"https://api.github.com/repos/biocore/emperor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/emperor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/emperor/teams","hooks_url":"https://api.github.com/repos/biocore/emperor/hooks","issue_events_url":"https://api.github.com/repos/biocore/emperor/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/emperor/events","assignees_url":"https://api.github.com/repos/biocore/emperor/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/emperor/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/emperor/tags","blobs_url":"https://api.github.com/repos/biocore/emperor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/emperor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/emperor/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/emperor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/emperor/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/emperor/languages","stargazers_url":"https://api.github.com/repos/biocore/emperor/stargazers","contributors_url":"https://api.github.com/repos/biocore/emperor/contributors","subscribers_url":"https://api.github.com/repos/biocore/emperor/subscribers","subscription_url":"https://api.github.com/repos/biocore/emperor/subscription","commits_url":"https://api.github.com/repos/biocore/emperor/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/emperor/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/emperor/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/emperor/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/emperor/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/emperor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/emperor/merges","archive_url":"https://api.github.com/repos/biocore/emperor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/emperor/downloads","issues_url":"https://api.github.com/repos/biocore/emperor/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/emperor/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/emperor/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/emperor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/emperor/labels{/name}","releases_url":"https://api.github.com/repos/biocore/emperor/releases{/id}","deployments_url":"https://api.github.com/repos/biocore/emperor/deployments","created_at":"2013-01-22T18:27:18Z","updated_at":"2016-11-05T22:35:15Z","pushed_at":"2016-11-12T20:09:23Z","git_url":"git://github.com/biocore/emperor.git","ssh_url":"git@github.com:biocore/emperor.git","clone_url":"https://github.com/biocore/emperor.git","svn_url":"https://github.com/biocore/emperor","homepage":"http://emperor.microbio.me/uno","size":27318,"stargazers_count":35,"watchers_count":35,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":30,"mirror_url":null,"open_issues_count":93,"forks":30,"open_issues":93,"watchers":35,"default_branch":"new-api"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/emperor/pulls/554"},"html":{"href":"https://github.com/biocore/emperor/pull/554"},"issue":{"href":"https://api.github.com/repos/biocore/emperor/issues/554"},"comments":{"href":"https://api.github.com/repos/biocore/emperor/issues/554/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/emperor/pulls/554/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/emperor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/emperor/pulls/554/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/emperor/statuses/6d2855d9cbfbc1947329566ffa31e3af8f977322"}}}}
{"actor":{"display_login":"wasade"}}