From: Andreas M. <t3...@gm...> - 2016-01-29 16:25:50
|
Thanks for your input Fernando. I thought about cross-posting to Jupyter, but I'm glad you also saw it here :) That would help, but not solve all problems. I guess the Figure could hold a tag for referencing, too. It would be nice to get a tag and caption from matplotlib. Maybe Benjamin's reply would help with that. But it sounds like the figure has a single string attached (which is more the tag). I guess I can do IPython.display.Figure(matplotlib_figure, caption="stuff", tag="tag") That would be acceptable, I think. But how do I reference that in a markup cell? [maybe I should move that question to the jupyter list, though] On 01/28/2016 10:17 PM, Fernando Perez wrote: > On Thu, Jan 28, 2016 at 3:23 PM, Andreas Mueller <t3...@gm... > <mailto:t3...@gm...>> wrote: > > Hi all. > > This is about a joint jupyter-notebook / matplotlib problem I've been > thinking about. > So I'm writing a book using jupyter-notebook, and all my figures are > generated using matplotlib. > > In books, there is usually a figure caption with a running number and > some description. > From what I read, the best way to add captions is just using > plt.text. > However, the caption should probably be in the markup, > not in a rendered PNG. I'm not sure if changing the backend might > help, > but that probably doesn't make the notebook happy? > > The other problem is that I want to have running numbers that I can > refer to by a tag (as you would in latex). > That is more of a notebook problem, though. > > Any feedback would be very welcome > > > I've been wanting to do something about this problem for a while, but > haven't had the cycles to work on it... Here's my current idea, > perhaps I can goad you into implementing it :) > > I think that IPython.display should provide a Figure object, capable > of wrapping any input image (with nice code to automatically swallow a > matplotlib figure without asking the user to convert it to an image > first), and taking an optional caption. > > Figure() would then produce as output the displayed image but with a > bit of nice CSS to center it on the page, along with the caption. > > The trick is to send the entire data bundle correctly structured so > that, at the other end, nbconvert could recognize these figures as > such, and not only produce nice HTML, but more importantly, push them > into the LaTeX output with the correct call to \figure, including > \caption as well as size and placement specifiers. > > The signature of Figure() might be something like > > def Figure(fig, caption=None, width=None, height=None, > latex_placement=None): > > > I would try implementing this first as a standalone tool, and once > it's been tested enough in real-world usage with both HTML and LaTeX > output from nbconvert, it could be merged in. I suspect it's going to > take a few iterations to get it right. > > But it's not particularly hard, and someone working on a book would be > the perfect candidate to have enough test cases to be able to iterate > until happy ;) > > If you think you want to take a stab at this, don't hesitate to ping > us on the jupyter list. We can help with some of the more obscure > parts of getting this to work on nbconvert (and there may be things > I've overlooked in the sketch above). > > Cheers, > > f > > -- > Fernando Perez (@fperez_org; http://fperez.org) > fperez.net-at-gmail: mailing lists only (I ignore this when swamped!) > fernando.perez-at-berkeley: contact me here for any direct mail |