Opened 15 years ago

Closed 15 years ago

#1606 closed defect (fixed)

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

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

Status badges

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 William Stein 15 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 15 years ago by William Stein

Status: newassigned

Changed 15 years ago by William Stein

Attachment: trac-1606.patch added

comment:2 Changed 15 years ago by William Stein

Summary: plotting -- add aspect_ratio option to show command[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 15 years ago by Mike Hansen

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

Works for me.

comment:4 Changed 15 years ago by Michael Abshoff

Resolution: fixed
Status: assignedclosed

Merged in Sage 2.10.1.alpha1

Note: See TracTickets for help on using tickets.