python, pythontex and plots

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Sep 22 20:58:59 EDT 2013


I don't usually top post, but for this I'll make an exception because I 
have *no idea* what any of your post means.

Are you actually asking a question? I can't see a question mark in it, so 
there's no explicit question. Are you just sharing something interesting 
you have learned? Expecting us to read your mind and intuit what the 
question is?

Why do nearly, but not quite all, the lines in your post start with % or 
\  or sometimes both? It looks like Postscript rather than Python.

Perhaps you should try again, and this time don't assume that we're 
familiar with whatever it is you're doing. Remember to include natural 
language explaining what your problem is, what result you expected, what 
result you actually got. In this forum, use English please. This is 
*especially* critical if using an unusual technology that most people are 
not familiar with.

I strongly recommend that first you read this:

http://sscce.org/‎

Its written for Java developers, but the same basic principles apply for 
Python. Remember that the number one language you should be using for 
communication is natural language (English in this forum) and code only 
second.

Thank you.


Steve

On Sun, 22 Sep 2013 13:26:06 -0700, chitturk wrote:

> \documentclass[12pt]{article}
> \usepackage{graphicx}
> \usepackage{wrapfig} % Allows in-line images \usepackage{pythontex}
> \setpythontexworkingdir{.}
> \begin{document}
> 
> This is an example of using pythontex
> 
> \begin{pycode}
> 
> import pylab as p
> import numpy as np
> x = np.linspace(0.0,1.0,10)
> y = 2.0*x + 5.0
> xmax = max(x)
> ymax = max(y)
> p.plot(x,y)
> outputfile = 'myplot.png'
> p.savefig(outputfile)
> p.clf()
> 
> \end{pycode}
> 
> % this works fine, I can print the name of the output file, variables
> 
> The plot is named \py{outputfile}, the max in x was \py{xmax} and
> \py{ymax}
> 
> % now I would like to plot it, this works
> 
> \includegraphics[scale=0.75]{myplot.png}
> 
> % but when I do this
> 
> %\includegraphics[scale=0.75]{\py{outputfile}}
> 
> % I get
> 
> %! File ended while scanning definition of \filename at base. %<inserted
> text>
> %                }
> % no pdf
> 
> 
> 
> \end{document}




More information about the Python-list mailing list