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

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 close merge delete

Sort by » oldest newest most voted

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.

more