Skip to content
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

IPython Notebook: irregular marker edge for 'o' #4421

Closed
tritemio opened this issue May 12, 2015 · 7 comments · Fixed by #4422
Closed

IPython Notebook: irregular marker edge for 'o' #4421

tritemio opened this issue May 12, 2015 · 7 comments · Fixed by #4422
Assignees
Milestone

Comments

@tritemio
Copy link

In the notebook, using %matplotlib inline, plotting circle markers ('o') with size of 7 results in a rendering error:

plt.plot([1,2,3,4], [3,1,2,4], 'o', ms=7)

image

The problem is present also in the png produced by savefig.

Changing the marker size to 6 or 8 results in correct rendering.

This rendering issue is very annoying also because the ms=7 happens to be the default marker size in seaborn. In fact, I reported the bug there first (mwaskom/seaborn#557).

@mwaskom
Copy link

mwaskom commented May 12, 2015

Actually this may be either a regression in what %matplotlib inline is doing to the rcParams or in my memory. I thought that inline plots had a lower DPI but that the default plt.savefig behavior used dpi=100 (the matplotlib default), but I can't reproduce that. The plots that get saved when using %matplotlib inline end up with a lower DPI unless otherwise specified. This probably isn't a matplotlib issue after all.

@tacaswell tacaswell added this to the next point release milestone May 13, 2015
@tacaswell
Copy link
Member

I would suggest using %matplotlib notebook instead. Leaving figure interactivity on the table is leaving more than half the power of mpl on the table.

It looks like inline defaults to 72 dpi and reduces the figure size from (8, 6) -> (6, 4) https://github.com/ipython/ipykernel/blob/master/ipykernel/pylab/config.py. The resulting image is a a bit small that expected because inline also saves with bbox_inches='tight'.

fig, ax = plt.subplots(dpi=72)
ax.plot([1,2,3,4], [3,1,2,4], 'o', ms=7)

will reproduce this.

I am in the process a PR to address this issue.

@tritemio
Copy link
Author

@tacaswell thanks for fixing this issue. Regarding switching to %matplotlib notebook, I would need to add plt.close() for every new figure, whereas with %matplotlib inline a new figure is created by default. Or am I missing something?

@mwaskom
Copy link

mwaskom commented May 13, 2015

Woah I had always assumed was an unavoidably annoyance, not a bug. Thanks for jumping on it, @tacaswell

@tacaswell
Copy link
Member

It is a fun deep one too related to conditional snapping of the path used to draw the markers. Ended up reading some c++ to sort this out.

@tritemio Why do you want to close the figures? If you do that they are no longer interactive. It is better to add

fig, ax = plt.subplots()

when you want a new figure. There is a PR in the works to make interactive OO work much nicer (#4091)

tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 13, 2015
Set the _snap_threshold for 'o' markers to `np.inf` which
effectively turns it off.

This makes 'o' markers look more circular at all sizes at all dpi.

This change subtly changed several tests.

Closes matplotlib#4421
@tacaswell tacaswell self-assigned this May 13, 2015
@tritemio
Copy link
Author

@tacaswell, questions, can there be more 2 interactive figures in the notebook? Is it the rule that the procedural interface is interactive while the OO is not? Examples or docs to get started on this?

@tacaswell
Copy link
Member

There can be as many interactive figures open as you want, pyplot has a notion of what the 'current' axes is (plt.gca() to get it), but if you have a ref to any axes you can either operate on it directly with the OO interface (ex ax.plot(...) ) or set it as the current figure (plt.sca(ax)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants