Opened 15 years ago

Closed 15 years ago

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

Reported by: Owned by: William Stein William Stein major sage-2.10.1 graphics N/A

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.

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

comment:1 Changed 15 years ago by William Stein

Status: new → assigned

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 assigned → closed

Merged in Sage 2.10.1.alpha1

Note: See TracTickets for help on using tickets.