SageMath x-axis division of plotted function

Viewed 110

i am looking for a way to display just special values on the x-axis in a plot of a function on SageMath. (e.g. 0, pi/4, pi/2, 3pi/4, pi, ...)

Any suggestions?

1 Answers

The SageMath plotting documentation has examples of using ticks and tick_formatter.

They allow plots like the following:

sage: ticks = [pi/6, sorted({sin(a) for a in [0, pi/6 .. 2*pi]})]
sage: p = plot(sin, 0, 2*pi, ticks=ticks, tick_formatter=pi)
sage: p
Launched png viewer for Graphics object consisting of 1 graphics primitive

The sine function graph plotted with SageMath with pi-based labels on the x-axis

To save the plot:

sage: p.save('sine_function_plot.png', figsize=5)
Related