Opened 12 years ago

Closed 12 years ago

#1606 closed defect (fixed)

[with patch; positive review] plotting -- add aspect_ratio option to show command

Reported by: was Owned by: was
Priority: major Milestone: sage-2.10.1
Component: graphics Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

I've been looking for a plot.option that ensures a 1:1 aspect ratio for 2D plots (e.g. something like AspectRatio?->Automatic in Mma). Does this exist in Sage? I'm trying to set things up so that

circle((0,0),2).show()

shows a circle rather than an ellipse, regardless of the plot window dimensions. Apologies if this has already been covered somewhere.

We should just add

P.show(aspect_ratio="automatic")

etc., exactly as in Mathematica. The goal with 2d graphics in Sage is that they at least support all options that Mathematica has.

Anyway, here is a function show11 that works exactly like show(...), but it will always show with a 1:1 aspect ratio:

def show11(g, figsize=[5,4], **kwds):
    for k in ['xmin', 'xmax', 'ymin', 'ymax']:
        if kwds.has_key(k): g.__getattribute__(k)(kwds[k])
    scale = (g.xmax() - g.xmin())/(g.ymax() - g.ymin())
    g.show(figsize=[figsize[0], figsize[0]/scale], **kwds)
show11(plot(sin, 0, 5))
show11(circle((0,0), 2), xmin=-3, xmax=4)

-- William

Attachments (1)

trac-1606.patch (16.1 KB) - added by was 12 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 12 years ago by was

  • Status changed from new to assigned

Changed 12 years ago by was

comment:2 Changed 12 years ago by was

  • Summary changed from plotting -- add aspect_ratio option to show command to [with patch; needs review] plotting -- add aspect_ratio option to show command

By the way, I also removed explicit mention of mathematica and matlab in the file, in order to not get in trademark trouble with them.

The main point about this patch is that the notion of aspect_ratio implemented in it is different than in mathematica. It is very useful though in practice, and consistent with what we've implemented for 3d graphics.

comment:3 Changed 12 years ago by mhansen

  • Summary changed from [with patch; needs review] plotting -- add aspect_ratio option to show command to [with patch; positive review] plotting -- add aspect_ratio option to show command

Works for me.

comment:4 Changed 12 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from assigned to closed

Merged in Sage 2.10.1.alpha1

Note: See TracTickets for help on using tickets.