centering matplotlib inline plots in ipython notebooks?
2,089 views
Skip to first unread message
dataholiks...@gmail.com
unread,
Jun 10, 2015, 3:41:43 PM6/10/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jup...@googlegroups.com
Hi,
Apologies if this is not the correct place to ask this question. Is there an *easy* way to center inline plots in an ipython notebook? I have looked around online but could not find any pointers except perhaps writing a custom css file.
Dataholik.
Brian Granger
unread,
Jun 10, 2015, 7:23:33 PM6/10/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jup...@googlegroups.com
CSS is going to be the way of getting this done. I don't see any other
way for now.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jup...@googlegroups.com
> On Jun 10, 2015, at 16:23, Brian Granger <elli...@gmail.com> wrote:
>
> CSS is going to be the way of getting this done. I don't see any other
> way for now.
The problem is the container are flexible to allow things to overflow. So getting the css to center things with unknown width might be hard.
—
M
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jup...@googlegroups.com
A quick-and-dirty way of doing it would be to wrap the matplotlib figure in a class which provides a custom _html_repr_() method so that the appearance can be tweaked. Here is a quick example:
(This requires Python 3; in principle it also works with Python 2 but some of the imports and definitions need to be adapted. Also, it may not be necessary to include the raw image data in the <img> tag. This is just copied & pasted from some code that I had lying around where I needed to do it like this.)
I appreciate it's rather kludgy and I'm not recommending to do it this way, but something along these lines might provide a quick fix if you can't get it to work any other way.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jup...@googlegroups.com
Thanks all for your suggestions. I am familiar with html/css/json but have never dug into the notebook format/raw files. I suppose it's time to roll up my sleeves and get dirty :).