Fix tutorial pyplot scales (issue #6775) #6779

Merged
merged 2 commits into from Jul 18, 2016

Conversation

Projects
None yet
5 participants
Contributor

afvincent commented Jul 17, 2016

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 added some commits Jul 17, 2016

@afvincent afvincent Suppr. minor y-ticklabels w/ logit scale 261dbf4
@afvincent afvincent Tweak linthreshy to avoid overlap of y-ticklabels
c97fea9

mdboom added the needs_review label Jul 17, 2016

Contributor

afvincent commented Jul 17, 2016

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.

Owner

jenshnielsen commented Jul 17, 2016

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 merged commit a4fdd60 into matplotlib:master Jul 18, 2016

2 of 3 checks passed

coverage/coveralls Coverage decreased (-0.002%) to 70.367%
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

tacaswell removed the needs_review label Jul 18, 2016

@tacaswell tacaswell added a commit that referenced this pull request Jul 18, 2016

@tacaswell tacaswell Merge pull request #6779 from afvincent/fix_tutorial_pyplot_scales
Fix tutorial pyplot scales

close issue #6775
e2b1184
Owner

tacaswell commented Jul 18, 2016 edited by QuLogic

backported to v2.x as e2b1184

Contributor

afvincent commented Jul 18, 2016

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

Owner

jenshnielsen commented Jul 18, 2016

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