Ask Your Question
1

How to specify x and y axis values in Sage plot?

asked 2018-03-04 17:28:19 +0100

anonymous user

Anonymous

updated 2018-03-04 17:29:53 +0100

So, I have three lists in Sage, and I want to combine two list plots, where in one of them I have the expected values, and in the other one I have the simulation results, and the third one is the x-axis values that corresponds to these points. So my lists (all same size), look like this:

# all lists removed partially for brevity
expected  = [47.4246, 47.9955, 95.9383]
simulated = [47.2, 48, 96]
primes    = [23327, 3009311, 886463]

# plotting
p = list_plot(expected, color='blue', marker='o') + list_plot(simulated, color='red', marker='x')
p.save('plot.svg')

Now, this creates a plot, and the y-axis corresponds to the values in expected and simulated lists, but I do not know how to incorporate the values in primes to the x-axis. So that I have 47.4246 for expected and 47.2 for simulated in the y-axis when I have 23327 in x-axis, and so on. Any ideas how to do this in Sage?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-03-04 17:56:05 +0100

tmonteil gravatar image

updated 2018-03-04 17:57:47 +0100

There is the zip function to transform two lists of the same length into a single list of tuples:

sage: zip(primes,expected)
[(23327, 47.4246000000000),
 (3009311, 47.9955000000000),
 (886463, 95.9383000000000)]

Then you can consider them as a list of 2d points to be plotted:

sage: p = list_plot(zip(primes,expected), color='blue', marker='o') + list_plot(zip(primes,simulated), color='red', marker='x')

Remark : you can (equivalently) use points or points2d instead of list_plot.

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: 2018-03-04 17:28:19 +0100

Seen: 1,030 times

Last updated: Mar 04 '18