# Formatting Plots (list_plot)

Hi All,

Sorry if this is going to be a silly question, but being new to Sage, I am struggling to find answers. I am creating a plot using list_plot (its a zip of two lists). Actually, I have 2 plots overlaid, which works fine.

I just can't figure out how to format the plot. I want to be in control of:

• Scales of axis (e.g. my x-axis is 0-360, but the divisions by default are in 50s. I want to show 0/90/180/270/360)
• the divisions of th Y axis, say every 500. Can you control both major and minor ticks?
• The linestyle of both individual plots

So I am just unsure how to do this formatting, especially with list_plot(), as all the documentation I have found is based on just plot()

edit retag close merge delete

2

For the ticks, check out similar questions such as http://ask.sagemath.org/question/23596/ (find more by searching for "tick" in the ask-sage search box). Can you provide a minimal example that people who want to help can start from?

I think the biggest thing I found was that by default, list_plot just plots points. After setting plotjoined=True that helped a lot!

Sort by » oldest newest most voted

If I understand correctly you have something like that:

import numpy as np
x = np.arange(0, 2 * np.pi, .1)
a = np.cos(x)
b = np.sin(x)


And you plot it like that:

P = list_plot(zip(x, a))
P += list_plot(zip(x, b))
P


It will lead to the plot of two sets of points with ticks .5 for y axis and 1 for the x axis. You may consider switching from list_plot to line and also specify ticks manually. Here is the set of custom parameters I typically use during plotting:

P = line(zip(x, a), linestyle='--', legend_label='$cos(x)$', thickness=4)
P += line(zip(x, b), color='black', legend_label='$sin(x)$', marker='o')
P.show(axes=False, frame=True, gridlines=True, ticks=(.5, .2), title='Plotting of $sin(x)$ and $cos(x)$')

more