ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 28 Feb 2015 01:42:07 +0100Formatting Plots (list_plot)https://ask.sagemath.org/question/25940/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()
Thanks in advance.Thu, 26 Feb 2015 11:58:20 +0100https://ask.sagemath.org/question/25940/formatting-plots-list_plot/Comment by slelievre for <p>Hi All,</p>
<p>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. </p>
<p>I just can't figure out how to format the plot. I want to be in control of:</p>
<ul>
<li>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)</li>
<li>the divisions of th Y axis, say every 500. Can you control both major and minor ticks?</li>
<li>The linestyle of both individual plots</li>
</ul>
<p>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()</p>
<p>Thanks in advance.</p>
https://ask.sagemath.org/question/25940/formatting-plots-list_plot/?comment=25941#post-id-25941For 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?Thu, 26 Feb 2015 14:34:32 +0100https://ask.sagemath.org/question/25940/formatting-plots-list_plot/?comment=25941#post-id-25941Comment by j0nr for <p>Hi All,</p>
<p>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. </p>
<p>I just can't figure out how to format the plot. I want to be in control of:</p>
<ul>
<li>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)</li>
<li>the divisions of th Y axis, say every 500. Can you control both major and minor ticks?</li>
<li>The linestyle of both individual plots</li>
</ul>
<p>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()</p>
<p>Thanks in advance.</p>
https://ask.sagemath.org/question/25940/formatting-plots-list_plot/?comment=25945#post-id-25945I think the biggest thing I found was that by default, list_plot just plots points. After setting plotjoined=True that helped a lot!Fri, 27 Feb 2015 12:12:23 +0100https://ask.sagemath.org/question/25940/formatting-plots-list_plot/?comment=25945#post-id-25945Answer by Eugene for <p>Hi All,</p>
<p>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. </p>
<p>I just can't figure out how to format the plot. I want to be in control of:</p>
<ul>
<li>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)</li>
<li>the divisions of th Y axis, say every 500. Can you control both major and minor ticks?</li>
<li>The linestyle of both individual plots</li>
</ul>
<p>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()</p>
<p>Thanks in advance.</p>
https://ask.sagemath.org/question/25940/formatting-plots-list_plot/?answer=25958#post-id-25958If 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)$')
Sat, 28 Feb 2015 01:42:07 +0100https://ask.sagemath.org/question/25940/formatting-plots-list_plot/?answer=25958#post-id-25958