-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
High quality inline SVG figures for notebook. #1881
Conversation
I just want to record here what I said on the list about this topic, I hadn't seen the PR... On Thu, Jun 7, 2012 at 2:50 PM, Bob McElrath bob+ipython@mcelrath.org wrote:
Unfortunately it's much more complicated than that. I experimented a I would love to be able to switch to SVG by default, but until we The problem with fixing this is that I've never been able to see the I'll make it a priority from now on to try to at least record these |
I suspected everyone wanted SVG, but as soon as I turned it on, it was obvious why you didn't make it the default. I think it's clear that the matplotlib svg backend has not received as much love as the others. Anyway I'll keep this branch here, and I for one will be using it with full-blown research datasets. I'll try to document any badness I encounter. BTW, @fperez did you ever try using the Cairo backend, and asking it to output svg instead of using the mpl-svg backend? I suspect that will squash most of the cases you're talking about. |
Seems like Cairo may be harder to count on for Windows users. |
@mcelrath no, I didn't even know I could get svg out of the cairo backend in matplotlib! Learn something new every day :) |
I switched the backend to Cairo, but unfortunately the Cairo backend has some kind of font problem. Strings (axis labels, title) sometimes come out as though a cat walked across the keyboard, instead of the intended string. To switch to the Cairo backend: change line 13 of
to:
(That's all it takes, it seems). None of the other backends will generate svg. To demonstrate the Cairo font problem, it seems to occur always with the second figure, so enter this in a cell:
It was mentioned somewhere that the svg backend has some bugs as well. I've seen this too, for me I often get histograms where the bars extend below the horizontal axis. I don't have a reliable recipe to reproduce it, but maybe that suggestion will be useful to someone. |
Mmh, if this last one is repeatable, it's definitely worth reporting upstream to mpl. @ivanov, you're our dual-project guru, have you guys seen this before in mpl? |
Given the recent detailed post on SVG issues, any changes on this front are obviously material for discussion in the 0.14 timeframe, tagging as such. |
Pinging the status of this PR. Needs to be rebased. @mcelrath what do you think needs to be done on this one? |
Conflicts: IPython/core/pylabtools.py IPython/zmq/pylab/backend_inline.py
It has been rebased. Only conflict was some code I added to make svg's transparent (makes it easier Brian E. Granger [notifications@github.com] wrote:
"The individual has always had to struggle to keep from being overwhelmed by |
original_axes_colors.append((patch.get_facecolor(), | ||
patch.get_edgecolor())) | ||
patch.set_facecolor(fc) | ||
patch.set_edgecolor(fc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: s/fc/ec/
You merged upstream master into this branch a few times. Please avoid doing that by using |
@@ -56,7 +56,7 @@ def _config_changed(self, name, old, new): | |||
inline backend.""" | |||
) | |||
|
|||
figure_format = CaselessStrEnum(['svg', 'png'], default_value='png', config=True, | |||
figure_format = CaselessStrEnum(['svg', 'png'], default_value='svg', config=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not change the default value. This PR makes the SVGs sharper, but does not actually fix the many problems with SVG figures that prompted us to change to PNG from SVG in the first place.
@mcelrath, let us know if you need a hand with rebasing this so there are no merges from master. A PR should never have any merges from master into it, as that makes the DAG and the PR harder to analyze, since new code from master shows up in the PR itself. |
Pinging the status of this PR. When this is done, Is there any things to add, or could it be merged into master ? |
@fperez I would like to merge this one but the rebase is beyond my git ninja skills. Do you (or someone else) want to have a go at it? Or should be just merge it as is? |
@@ -40,12 +40,12 @@ def _config_changed(self, name, old, new): | |||
# The typical default figure size is too large for inline use, | |||
# so we shrink the figure size to 6x4, and tweak fonts to | |||
# make that fit. | |||
rc = Dict({'figure.figsize': (6.0,4.0), | |||
rc = Dict({'figure.figsize': (32.0,20.0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won' this change the figure size of all figure types, not just svg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the proportions of the figures was not preserved. Is there a reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have confirmed that this resizing of figures completely messes up non-svg figures. We simply can't do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These size changes were done because they improve the appearance of SVG figures.
With lower figsize, pixelation and aliasing occurs, which makes SVG's look like
shit. I still do not fully understand why this occurs, but simply increasing
these sizes visually fixes it on screen.
I would be happy to understand why SVG, which is supposed to be a vector format,
has such problems with pixelation and aliasing. This occurs cross-browser, and
even in inkscape, IIRC. I suspect the matplotlib output code, but was unable to
identify what it was putting in the SVG file that caused it.
Brian E. Granger [notifications@github.com] wrote:
In IPython/zmq/pylab/backend_inline.py:
@@ -40,12 +40,12 @@ def _config_changed(self, name, old, new):
# The typical default figure size is too large for inline use,
# so we shrink the figure size to 6x4, and tweak fonts to
# make that fit.
- rc = Dict({'figure.figsize': (6.0,4.0),
- rc = Dict({'figure.figsize': (32.0,20.0),
Won' this change the figure size of all figure types, not just svg?
Yes.
Also, the proportions of the figures was not preserved. Is there a reason for
this?
Solely aesthetic on my screen.
Brian E. Granger [notifications@github.com] wrote:
In IPython/zmq/pylab/backend_inline.py:
# 12pt labels get cutoff on 6x4 logplots, so use 10pt.
'font.size': 10,
'font.size': 32,
The font size increase is also not proportional. Comments?
Again, chosen by just looking at it and seeing that it looks nice.
Cheers, Bob McElrath
"The individual has always had to struggle to keep from being overwhelmed by
the tribe. If you try it, you will be lonely often, and sometimes frightened.
But no price is too high to pay for the privilege of owning yourself."
-- Friedrich Nietzsche
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I would prefer if we scaled the image proportions and font sizes in the same was.
But, have we asked the mpl devs about the SVG resolution question?
I am going to close this PR because of inactivity. We would love to have this work finished and merged, but we are going to close this PR until work resumes. I have created an issue to track this PR #2647. I have left comments detailing what needs to be addressed. Here are the highlights:
Again, we would love to see this work started, but we like to keep our PR queue with work that is actively progressing. Please feel free to reopen these things are moving forward. |
Brian E. Granger [notifications@github.com] wrote:
Changing the figure and font sizes is really all that is required to make These sizes are a ridiculous pile of imaginary device measurements anyway (pt,
Will do. |
OK, |
Per @ellisonbg's request, I'm submitting this pull request as a place to work on and discuss SVG figures in the notebook. See also #1832.
The basic things I've written so far are:
IPython.core.pylabtools.print_figure()
to make figures transparent for web use, followingmatplotlib.savefig()
.