Opened 8 years ago

Closed 7 years ago

#14782 closed defect (fixed)

empty ticks result in empty axes in log scale

Reported by: ppurka Owned by: jason, was
Priority: major Milestone: sage-6.3
Component: graphics Keywords:
Cc: kcrisman Merged in:
Authors: Punarbasu Purkayastha Reviewers: Karl-Dieter Crisman
Report Upstream: N/A Work issues:
Branch: fbc55f4 (Commits, GitHub, GitLab) Commit: fbc55f498f01beace1622d3cae176f841a8d1cbf
Dependencies: Stopgaps:

Status badges


The axes do not get plotted in this


whereas they do get plotted in linear scale


Change History (17)

comment:1 Changed 8 years ago by kcrisman

  • Cc kcrisman added

comment:2 Changed 8 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:3 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:4 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:5 Changed 7 years ago by ppurka

  • Branch set to u/ppurka/ticket/14782

comment:6 Changed 7 years ago by ppurka

  • Authors set to Punarbasu Purkayastha
  • Commit set to a4e6c88c8218545d7b1be8970d83e3c38687435d
  • Status changed from new to needs_review

This patch should fix empty axes in log scale.

New commits:

a4e6c88fix or workaround for no axes in log scale when ticks are off

comment:7 Changed 7 years ago by kcrisman

Dumb question - is this because bbox_extra_artists=self._bbox_extra_artists wasn't added when fig_tight wasn't True? (Where those extra artists are presumably the axes and fig_tight wasn't set in log scale or something?) Just want to know why this works before I test that it does work :)

comment:8 Changed 7 years ago by ppurka

The problem seems to stem from the bbox_extra_artists being an empty list. Having fig_tight true or false is not the main point here.

It seems quite hard to reproduce this problem directly in matplotlib.pyplot. One really needs to use the internal commands in mpl and save figure via FigureCanvasAgg to see this bug. Actually, I do not know if it is a problem with the way sage calls the mpl commands, or if it is a real bug in mpl. If it is a bug in mpl, then it is a very subtle bug because the following command gives us back the axes:

plot_loglog(x^2,(x,1,100), ticks=[[],[]], axes_labels=['x','y'])

comment:9 Changed 7 years ago by ppurka

To add to/clarify my previous post.. it is a combination of both fig_tight and bbox_extra_artists, i.e., fig_tight=True and bbox_extra_artists=[] triggers the bug. fig_tight=True seems to be the default in Sage.

comment:10 Changed 7 years ago by ppurka

Here is a "minimal" (really???!!!) code to reproduce it in matplotlib

from matplotlib.figure import Figure
from matplotlib.ticker import NullLocator
from matplotlib.backends.backend_agg import FigureCanvasAgg
import matplotlib.lines as lines
subplot = figure.add_subplot(111)
subplot.add_line(lines.Line2D(range(10), range(10)))



figure.savefig('a.png', bbox_inches='tight', bbox_extra_artists=[])

Things which bring back the axes:

  1. Set the outward parameter a bit less
    subplot.spines['bottom'].set_position(('outward',7)) # just barely
  2. Either remove bbox_inches='tight' or bbox_extra_artists=[] from the savefig command.
Version 0, edited 7 years ago by ppurka (next)

comment:11 Changed 7 years ago by kcrisman

Weird, though I believe this probably is minimal, after reading the graphics code for the axes again. I'll let you decide whether this is a mpl bug and whether to report it upstream; it may be intended behavior.

In fact, what this also fixes is the following, which was missed before because the axes were so big they were drawn to touch.

sage: plot(x^2,(x,1,2),ticks=[[],[]])


sage: plot(x^2,(x,1,2),ticks=[[],[3,4]])

was only missing one axis. So it is really tight, no extra artists, and no (or few) ticks that does it! Quite a combination.

So positive review to your fix! Do you want to include a doctest? I don't know that we could automatically check for this - I poked around with P.matplotlib() for a while trying to get access to this but couldn't find something telling me it was invisible, and in fact it still seems to have all the attributes that would automatically accrue to it.

comment:12 follow-up: Changed 7 years ago by ppurka

I do not know how to doctest this. That's why there is no doctest included.

As for whether it is an mpl bug or not, I am quite divided. It is the Sage code which sets (outward,10) for the axis. I am not sure if this is intended behavior. It is definitely not default behavior for mpl.

comment:13 in reply to: ↑ 12 Changed 7 years ago by kcrisman

I do not know how to doctest this. That's why there is no doctest included.

I suppose one could just include a plot like plot(x^2,(x,1,2),ticks=[[],[]]) as a doctest, with a comment pointing out "fixes :trac:14782" or something. We do that occasionally when there is no other way to do so. If it's not too much trouble, I think that would be good - could certainly go in an obscure part of TESTS: or something.

comment:14 Changed 7 years ago by kcrisman

  • Reviewers set to Karl-Dieter Crisman

comment:15 Changed 7 years ago by git

  • Commit changed from a4e6c88c8218545d7b1be8970d83e3c38687435d to fbc55f498f01beace1622d3cae176f841a8d1cbf

Branch pushed to git repo; I updated commit sha1. New commits:

fbc55f4add a doctest

comment:16 Changed 7 years ago by kcrisman

  • Status changed from needs_review to positive_review

Thanks, glad you concur.

comment:17 Changed 7 years ago by vbraun

  • Branch changed from u/ppurka/ticket/14782 to fbc55f498f01beace1622d3cae176f841a8d1cbf
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.