8000 Fix tutorial pyplot scales (issue #6775) by afvincent · Pull Request #6779 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix tutorial pyplot scales (issue #6775) #6779

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

Merged
merged 2 commits into from
Jul 18, 2016

Conversation

afvincent
Copy link
Contributor

Fix #6775.

The issue reports among other things a poor choice of x-ticks. However, this seems to be OK in the devdocs version (http://matplotlib.org/devdocs/users/pyplot_tutorial.html)

I suppressed the minor y tick labels in the case of the logit scale, to keep only the major ones. To do so, I used a NullFormatter: is it OK for a pyplot tutorial? First I wanted to simply use plt.minorticks_off but it hides the nice feature of the logit scale, which is to be log in some range and linear in another range.

Furthermore, I slightly tweaked the linthreshy value in the case of the symlog case, to avoid overlapping some of the y tick labels.

The current PR should produce things similar to
example_with_plt_subplots_adjust
I precise “similar” because depending on the random samples, the tick range of the axes may be different.

PS: I got weird crashes when trying to use plt.tight_layout to adjust the subplots. I'll see if it comes from my machine or is a real issue, and I will open report another issue in the latter case. And for the moment, I have simply defined by hand some correct values in plt.subplots_adjust.

@afvincent
Copy link
Contributor Author

Definitively, if I remove the plt.subplots_adjust and try to rely on plt.tight_layout instead, I get this traceback (with Python 2.7 in a conda env, Linux, mpl 2.0.0b3.post1796+gd527799):

QGtkStyle could not resolve GTK. Make sure you have installed the proper libraries.
/home/adrien/matplotlib/lib/matplotlib/transforms.py:380: RuntimeWarning: invalid value encountered in double_scalars
  return points[1, 0] - points[0, 0]
/home/adrien/matplotlib/lib/matplotlib/tight_layout.py:199: RuntimeWarning: invalid value encountered in double_scalars
  kwargs["wspace"] = hspace / h_axes
/home/adrien/matplotlib/lib/matplotlib/axis.py:1008: UserWarning: Unable to find pixel distance along axis for interval padding of ticks; assuming no interval padding needed.
  warnings.warn("Unable to find pixel distance along axis "
/home/adrien/matplotlib/lib/matplotlib/axis.py:1018: UserWarning: Unable to find pixel distance along axis for interval padding of ticks; assuming no interval padding needed.
  warnings.warn("Unable to find pixel distance along axis "
Traceback (most recent call last):
  File "/home/adrien/matplotlib/lib/matplotlib/backends/backend_qt5agg.py", line 182, in __draw_idle_agg
    FigureCanvasAgg.draw(self)
  File "/home/adrien/matplotlib/lib/matplotlib/backends/backend_agg.py", line 464, in draw
    self.figure.draw(self.renderer)
  File "/home/adrien/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/adrien/matplotlib/lib/matplotlib/figure.py", line 1262, in draw
    renderer, self, dsu, self.suppressComposite)
  File "/home/adrien/matplotlib/lib/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/adrien/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/adrien/matplotlib/lib/matplotlib/axes/_base.py", line 2383, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File "/home/adrien/matplotlib/lib/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/adrien/matplotlib/lib/matplotlib/artist.py", line 68, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/adrien/matplotlib/lib/matplotlib/axis.py", line 1109, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/home/adrien/matplotlib/lib/matplotlib/axis.py", line 942, in _update_ticks
    tick_tups = [t for t in self.iter_ticks()]
  File "/home/adrien/matplotlib/lib/matplotlib/axis.py", line 885, in iter_ticks
    majorLocs = self.major.locator()
  File "/home/adrien/matplotlib/lib/matplotlib/ticker.py", line 1721, in __call__
    return self.tick_values(vmin, vmax)
  File "/home/adrien/matplotlib/lib/matplotlib/ticker.py", line 1726, in tick_values
    locs = self._raw_ticks(vmin, vmax)
  File "/home/adrien/matplotlib/lib/matplotlib/ticker.py", line 1674, in _raw_ticks
    nbins = max(min(self.axis.get_tick_space(), 9),
  File "/home/adrien/matplotlib/lib/matplotlib/axis.py", line 2008, in get_tick_space
    return int(np.floor(length / size))
ValueError: cannot convert float NaN to integer

I don't understand everything, but it looks like plt.tight_layout has difficulties to place some ticks.

@jenshnielsen
Copy link
Member

Looks good. I think the tight_layout issue is something that we should investigate further. Will you create an issue for that so we can merge this without it?

@tacaswell tacaswell added this to the 2.0 (style change major release) milestone Jul 17, 2016
@tacaswell tacaswell merged commit a4fdd60 into matplotlib:master Jul 18, 2016
tacaswell added a commit that referenced this pull request Jul 18, 2016
@tacaswell
Copy link
Member
tacaswell commented Jul 18, 2016

backported to v2.x as e2b1184

@afvincent
Copy link
Contributor Author

@jenshnielsen I've just created a dedicated issue (#6789) as you suggested.

@jenshnielsen
Copy link
Member

Thanks @afvincent thats great and a very detailed issue :)

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

Successfully merging this pull request may close these issues.

5 participants
0