sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.43k stars 478 forks source link

Control subticks in 2d plot #14995

Open kcrisman opened 11 years ago

kcrisman commented 11 years ago

In Ask Sage question 691, the very reasonable question of controlling subticks was asked. Meanwhile, Mark Edgington has implemented this!

Here is a description, from the Ask Sage question and answer, of the new functionality:

Here's an example which should achieve what was sought after by the questioner (except that minor ticks are smaller than major ticks, which may not have been desired):

var('x')
p = plot(5*sin(x/10)*sin(x), (x, 0, 20*pi))
p.show(ticks=[[0, 5*pi, 10*pi, 15*pi, 20*pi], 5],
       minor_ticks=pi, tick_formatter="latex")

If the minor_ticks option is not specified, then minor-tick behavior will follow previous Sage defaults. If the option is specified, then the following examples describe the behavior:

  • minor_ticks=None, or =[None, None] -- no minor ticks will appear on either x or y axes
  • minor_ticks=3 -- minor ticks every 3 units on x axis; Sage defaults on y axis
  • minor_ticks=[3, None] -- minor ticks every 3 units on x axis; none on y axis
  • minor_ticks=[3, [2, 7]] -- minor ticks every 3 units on x axis; at 2 and 7 on y axis

This was made available, as based on Sage 5.10, on bitbucket.

A branch would be needed, with doctests. Some of the stuff on that branch is also for other issues like #8478.

The bitbucket repo is gone, but archived at Software Heritage.

CC: @kcrisman @slel

Component: graphics

Issue created by migration from https://trac.sagemath.org/ticket/14995

slel commented 3 years ago
comment:4

Updating ticket description with Software Heritage link.

Hoping this can be revived.

slel commented 3 years ago

Description changed:

--- 
+++ 
@@ -1,18 +1,39 @@
-In [this ask.sagemath question](http://ask.sagemath.org/question/691/subticks-in-2d-plot#3839), the very reasonable question of controlling subticks was asked.  Meanwhile, Mark Edgington has implemented this!
+In [Ask Sage question 691](http://ask.sagemath.org/question/691/subticks-in-2d-plot#3839),
+the very reasonable question of controlling subticks was asked.
+Meanwhile, Mark Edgington has implemented this!

-Here is a description from that question of the new functionality:
+Here is a description, from the Ask Sage question and answer,
+of the new functionality:

-```
-Here's an example which should achieve what was sought after by the questioner (except that minor ticks are smaller than major ticks, which may not have been desired) :
-var('x')
-p=plot(5*sin(x/10)*sin(x),(x,0,20*pi))
-p.show(ticks=[[0,5*pi,10*pi,15*pi,20*pi],5], minor_ticks=pi,
-       tick_formatter="latex")
-If the minor_ticks option is not specified, then minor-tick behavior will follow previous Sage defaults. If the option is specified, then the following examples describe the behavior:
-minor_ticks=None, or =[None,None] -- no minor ticks will appear on either x or y axes
-minor_ticks=3 -- minor ticks every 3 units on x axis ; Sage defaults on y axis
-minor_ticks=[3,None] -- minor ticks every 3 units on x axis ; none on y axis
-minor_ticks=[3,[2,7]] -- minor ticks every 3 units on x axis ; at 2 and 7 on y axis
-```
+> Here's an example which should achieve what was sought after
+> by the questioner (except that minor ticks are smaller than
+> major ticks, which may not have been desired):
+> 
+> ```
+> var('x')
+> p = plot(5*sin(x/10)*sin(x), (x, 0, 20*pi))
+> p.show(ticks=[[0, 5*pi, 10*pi, 15*pi, 20*pi], 5],
+>        minor_ticks=pi, tick_formatter="latex")
+> ```
+> If the `minor_ticks` option is not specified, then minor-tick
+> behavior will follow previous Sage defaults. If the option is
+> specified, then the following examples describe the behavior:
+> - `minor_ticks=None`, or `=[None, None]` -- no minor ticks
+>   will appear on either x or y axes
+> - `minor_ticks=3` -- minor ticks every 3 units on x axis;
+>   Sage defaults on y axis
+> - `minor_ticks=[3, None]` -- minor ticks every 3 units
+>   on x axis; none on y axis
+> - `minor_ticks=[3, [2, 7]]` -- minor ticks every 3 units
+>   on x axis; at 2 and 7 on y axis

-Currently this lives, as based on Sage 5.10, on [bitbucket](https://bitbucket.org/edgimar/sage-main/compare#diff).  A patch would be needed, with doctests.  Some of the stuff on that branch is also [for other issues](https://bitbucket.org/edgimar/sage-main/commits/8f2d381fae7eb0e8de92ecab9f12f4b1d3ef951e) like #8478.
+This was made available, as based on Sage 5.10,
+on [bitbucket](https://bitbucket.org/edgimar/sage-main/compare#diff).
+
+A branch would be needed, with doctests.
+Some of the stuff on that branch is
+also [for other issues](https://bitbucket.org/edgimar/sage-main/commits/8f2d381fae7eb0e8de92ecab9f12f4b1d3ef951e) like #8478.
+
+The bitbucket repo is gone,
+but [archived at Software Heritage](https://archive.softwareheritage.org/browse/origin/directory/?origin_url=https://bitbucket.org/edgimar/sage-main).
+
mkoeppe commented 3 years ago
comment:5

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

goebbe commented 3 years ago
comment:6

Not sure if this is really relevant for this specific ticket. The following code can be used to get some control about the appearance of the major or minor ticks:

import matplotlib
from pylab import figure, show
matplotlib.rcParams.update({'xtick.major.size':4})   #length
matplotlib.rcParams.update({'ytick.major.size':4})   #length
matplotlib.rcParams.update({'xtick.minor.size':2})   #length
matplotlib.rcParams.update({'ytick.minor.size':0})   #length 0 = no minor ticks on y-axis
matplotlib.rcParams.update({'lines.markeredgewidth':2})  #width of ticks
matplotlib.rcParams.update({'lines.markersize':6})       #size of ticks

However, implementing fine grained control, may be beyond the scope of this ticket.

Currently (Sage 9.2) None is used if the major ticks on an axis are NOT changed. If ticks should not be shown this is used: ticks=[[],[]]) Note that this is different from what is proposed in the description of this ticket for minor_ticks.

https://doc.sagemath.org/html/en/reference/plotting/sage/plot/graphics.html?highlight=tick