Ask Your Question
1

Formatting Plots (list_plot)

asked 2015-02-26 11:58:20 +0100

j0nr gravatar image

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()

Thanks in advance.

edit retag flag offensive close merge delete

Comments

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?

slelievre gravatar imageslelievre ( 2015-02-26 14:34:32 +0100 )edit

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

j0nr gravatar imagej0nr ( 2015-02-27 12:12:23 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-02-28 01:42:07 +0100

Eugene gravatar image

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)$')
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-02-26 11:58:20 +0100

Seen: 1,656 times

Last updated: Feb 28 '15