[IPython-dev] IPython Notebook Diagrams

Andrew Gibiansky andrew.gibiansky@gmail....
Wed Feb 19 20:29:07 CST 2014


Hey all!

I've figured out one way to do this.

If we use something like %%tikz (if it or something like it exists) or just using Python to generate figures, then the only thing we want to do is hide the input cell and the In[] and Out[] from the nbconvert output. You can do this with templates:

If, in IPython notebook, you make cell headers be "edit metadata", and change metadata to something like {"display": "false"}, you can then change your templates to make nbconvert ignore those cells.

The relevant bits in basic.tpl that need to be modified look like this:

{% block output %}
<div class="output_area">
{%- if output.output_type == 'pyout' and cell.metadata.display != "false" -%}
<div class="prompt output_prompt">
Out[{{ cell.prompt_number }}]:
{%- else -%}
<div class="prompt">
{%- endif -%}
</div>
{{ super() }}
</div>
{% endblock output %}
and

{% block input_group -%}
    {%- if cell.metadata.display != "false" -%}
        <div class="input">
        {{ super() }}
        </div>
    {%- endif -%}
{% endblock input_group %}
Note how those templates check that cell.metadata.display is false, so it'll ignore things that we don't want to show!

It looks like there's plenty of extensions (such as Asymptote) for drawing pretty pictures, this pretty effectively solves the problem.

The only issue is that you have to have your own templates, which is sorta ugly, but ain't a big problem.

-- Andrew



On February 19, 2014 at 3:46:14 PM, Andrew Gibiansky (andrew.gibiansky@gmail.com) wrote:

That's really cool!

However, I'm looking for a solution such that the diagram code is hidden from the user. This would make it plausible to publish the result as a blog or something along those lines, where the code used to make the diagram is unnecessary, but the diagram itself is.

-- Andrew



On February 19, 2014 at 3:44:52 PM, Tavish Armstrong (tavisharmstrong@gmail.com) wrote:

On Wed, Feb 19, 2014 at 03:37:24PM -0800, Andrew Gibiansky wrote:
> Hello,
>
> I am tired of needing to create diagrams externally and then either
> use Markdown links (which require the image to be exported and saved
> somewhere) or copy/pasting the base64 encoding of the image into the
> Markdown cell (which occasionally crashes my browser for big images).
> I would like to be able to create diagrams immediately within the
> Markdown cells.
>
> What's the best way to do this? I wanted to go with RaphaelJS and put
> <script> tags within Markdown cells, but it seems that that is broken
> on master due to bad parsing of quotes (though I've heard discussion
> that it'll be completely removed in 1.0, which leaves me confused,
> since it's clearly not completely removed...)
>
> How would you suggest going about this goal?

For very simple diagrams, you might want to take a look at %blockdiag
magic:

https://bitbucket.org/vladf/ipython-diags

It takes a cell containing...

%%blockdiag
{
a -> b -> c -> d;
c -> e;
e -> a;
}

and generates a block/sequence/activity diagram using that spec.

Hope this helps,
--
Tavish
_______________________________________________
IPython-dev mailing list
IPython-dev@scipy.org
http://mail.scipy.org/mailman/listinfo/ipython-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20140219/cb7e389a/attachment.html 


More information about the IPython-dev mailing list