How to specify the size of a figure with Pweave (using a .py script)

451 views Asked by At

I am trying to specify the size of a figure with Pweave inside a 'Pweave-compatible' .py script:

#' do the imports

import matplotlib.pyplot as plt

#' normal figure

plt.figure(1)
plt.plot(range(30), color='k', linestyle='dashed', marker='o')

#' figure super wide


#+ fig = True, width = '24 cm'
plt.figure(2)
plt.plot(range(30), color='k', linestyle='dashed', marker='o')

However after having compiled the script:

pypublish test.py

I can only witness that the figures are identical in the .html file where I would expect them to have different sizes.

I am wondering what I am doing wrong or even if this is supported (couldn't find a specific example or related statement in Pweave doc)

2

There are 2 answers

0
bobleponge On BEST ANSWER

Seeing the lack of popularity of Pweave and support, I decided to go with PyLatex, which for sure is not the same but allowed me to pretty much achieve what I wanted.

0
Matti Pastell On

As the author of Pweave I'm going to answer this as I just noticed it. You will need to set width that is valid html so setting width to e.g. 1200 will work.

The code sample below will change the figure size in HTML output:

#' figure super wide

#+ fig = True, width = '1200'

plt.figure(2)
plt.plot(range(30), color='k', linestyle='dashed', marker='o')

Also there is a bug in the script reader (in 0.23.2) that doesn't like the extra whitespace between #' and #+ lines (this is now fixed in github).

I have also added pweave tag on SO. So if anyone is asking