Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Commit

Permalink
Merge pull request #46 from ContinuumIO/youngblood/add_viz_to_docs
Browse files Browse the repository at this point in the history
Youngblood/add viz to docs
  • Loading branch information
msarahan committed Oct 15, 2015
2 parents e8e796e + 519ba03 commit 8727814
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 3 deletions.
Binary file added docs/_static/img/thumbnail_ldavis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/img/thumbnail_termite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Example syntax for these:
>>> termite = Termite(lda.termite_data(n_topics), "Termite Plot")
>>> termite.plot(os.path.join(dir_path, 'termite.html'))
.. raw:: html
:file: viz/termite_open.html

.. raw:: html
:file: viz/reviews_termite.html

.. code-block:: python
>>> from topik.viz import LDAvis
Expand All @@ -41,5 +47,11 @@ Example syntax for these:
>>> from topik.viz import plot_lda_vis
>>> plot_lda_vis(model.to_py_lda_vis())
.. raw:: html
:file: viz/ldavis_open.html

.. raw:: html
:file: viz/reviews_pyldavis.html

Each model is free to implement its own additional outputs - check the class
members for what might be available.
8 changes: 8 additions & 0 deletions docs/viz/ldavis_open.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha256-Sk3nkD6mLTMOF0EOpNtsIry+s1CsaqQC1rVLTAy+0yc= sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>

<h3>View LDAVis Plot</h3>
<button type="button" data-toggle="modal" data-target="#graphModal" style="margin-bottom:20px;border:none;">
<img src="_static/img/thumbnail_ldavis.png" alt="" style="width:330px;">
</button>
22 changes: 22 additions & 0 deletions docs/viz/modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Use this template for wrapping the LDA vis graph in a modal popup. -->

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha256-Sk3nkD6mLTMOF0EOpNtsIry+s1CsaqQC1rVLTAy+0yc= sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#graphModal" style="margin-bottom:20px;">
View LDAvis
</button>

<div class="modal fade" id="graphModal">
<div class="modal-dialog" style="width:1300px;height:800px;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">LDAVis Graph</h4>
</div>
<div class="modal-body">
<div class="plotdiv" id="d68d0c54-73fc-4fb7-a62c-01092a46f892"></div>
</div>
</div>
</div>
</div>
57 changes: 57 additions & 0 deletions docs/viz/reviews_pyldavis.html

Large diffs are not rendered by default.

244 changes: 244 additions & 0 deletions docs/viz/reviews_termite.html

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/viz/termite_open.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha256-Sk3nkD6mLTMOF0EOpNtsIry+s1CsaqQC1rVLTAy+0yc= sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>

<h3>View Termite Plot</h3>
<button type="button" data-toggle="modal" data-target="#termiteModal" style="margin-bottom:20px;border:none;">
<img src="_static/img/thumbnail_termite.png" alt="" style="width:330px;">
</button>
Binary file added docs/viz/thumbnail_ldavis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/viz/thumbnail_termite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions topik/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ def plot(self, output_file="termite.html"):
p.circle(x="topic", y="word", size="size", fill_alpha=0.6, source=data_source)
plt.show(p)

def plot_lda_vis(model_data):
def plot_lda_vis(model_data, mode='show', filename=None):
"""Designed to work with to_py_lda_vis() in the model classes."""
from pyLDAvis import prepare, show
from pyLDAvis import prepare, save_html, show
model_vis_data = prepare(**model_data)
show(model_vis_data)
if mode == 'save_html' and filename:
save_html(model_vis_data, filename)
else:
show(model_vis_data)

0 comments on commit 8727814

Please sign in to comment.