ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 04 Mar 2018 10:56:05 -0600How to specify x and y axis values in Sage plot?https://ask.sagemath.org/question/41393/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?Sun, 04 Mar 2018 10:28:19 -0600https://ask.sagemath.org/question/41393/how-to-specify-x-and-y-axis-values-in-sage-plot/Answer by tmonteil for <p>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:</p>
<pre><code># 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')
</code></pre>
<p>Now, this creates a plot, and the y-axis corresponds to the values in <code>expected</code> and <code>simulated</code> lists, but I do not know how to incorporate the values in <code>primes</code> 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?</p>
https://ask.sagemath.org/question/41393/how-to-specify-x-and-y-axis-values-in-sage-plot/?answer=41394#post-id-41394There 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`.Sun, 04 Mar 2018 10:56:05 -0600https://ask.sagemath.org/question/41393/how-to-specify-x-and-y-axis-values-in-sage-plot/?answer=41394#post-id-41394