Ask Your Question
1

How to edit minor ticks in points() plot

asked 2019-11-06 14:30:41 +0100

antoniomg gravatar image

Hey there,

I am working with various plots in the complex plane, for instance:

points([CDF(a // 5 - 3 + (a % 5 - 2)*i) for a in range(0, 35)])

How would one go about deleting the minor ticks? This is a particular case of the more general question: how does one gain finer control over matplotlib parameter when working with sage plotting primitives? (especially grids, axes, ticks, etc.).

I have tried passing Locator and Formatter arguments to points, but as far as I can tell this affects both major and minor ticks. I have also tried working with matplotlib objects direcly via points(...).matplotlib(), where one can then fine-tune those elements. But I cannot actually get it to plot what I would expect after modifying them.

Please help! And thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-11-07 04:16:20 +0100

Juanjo gravatar image

updated 2019-11-07 15:47:29 +0100

You can modify the aspect of the graphic through options of points (or point2d) or through the show method. Try this, for example:

sage: p = points([CDF(a // 5 - 3 + (a % 5 - 2)*i) for a in range(0, 35)], 
....: color="gray", marker="s", size=25)
sage: p.show(ticks=[[-3..3],None])

For a list of the graphic properties than can be changed through show options, type:

sage: p.SHOW_OPTIONS

For help about options, like color, marker or size, you can directly provide, type:

sage: point2d?

See also the documentation for points and graphics objects.

EDIT: Some graphic properties can be modified by changing matplotlib rcParams. This is the case of ticks size. Try the following code:

from matplotlib import rcParams, rcdefaults
from matplotlib.ticker import NullFormatter
rcParams['xtick.major.size'] = rcParams['xtick.minor.size'] = 0
rcParams['ytick.major.size'] = rcParams['ytick.minor.size'] = 0

points_dict = dict(color='red', size=25, marker='s', zorder=3)
grid_dict = dict(color='#AAABB8', linestyle='-')
show_dict = dict(ticks=[[-3..3],[-2..2]], tick_formatter=2*[NullFormatter()], 
                 gridlines=True, gridlinesstyle=grid_dict, aspect_ratio=1)
p = points([CDF(a // 5 - 3 + (a % 5 - 2)*I) for a in range(0, 35)], **points_dict)
p.show(**show_dict)

rcdefaults() # Just for comparison, reset rcParams...
p.show()     # ... and show points again with no particular option

The option zorder=3 included in points_dict serves to print points over the axes and gridlines. Check what happens without this option or using a lesser value.

edit flag offensive delete link more

Comments

Oh, this is so useful. Such a simple solution, but so hard to find. Muchas gracias ^^ One last small follow-up question (if I should ask this separately, let me know): is there a way to hide the actual tick marks (if that's what they're called; I mean the little dashes crossing the axes) while keeping the grid?

This is my current code:

from matplotlib.ticker import NullFormatter

glsdict=dict(color='#AAABB8', linestyle='-')

points([CDF(a // 5 - 3 + (a % 5 - 2)*I) for a in range(0, 35)], ticks=[[-3..3], [-2..2]], tick_formatter=2*[NullFormatter()], gridlines=True, gridlinesstyle=glsdict, aspect_ratio=1)
antoniomg gravatar imageantoniomg ( 2019-11-07 09:40:51 +0100 )edit

(To the EDIT) Such a complete answer! You made my day, thanks a lot.

antoniomg gravatar imageantoniomg ( 2019-11-07 16:18:46 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2019-11-06 14:30:41 +0100

Seen: 846 times

Last updated: Nov 07 '19