<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>scienceoss.com &#187; axis</title>
	<atom:link href="http://scienceoss.com/tags/axis/feed/" rel="self" type="application/rss+xml" />
	<link>http://scienceoss.com</link>
	<description>useful tidbits for using open source software in science</description>
	<lastBuildDate>Wed, 26 May 2010 03:34:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Change distance of tick labels from axis</title>
		<link>http://scienceoss.com/change-distance-of-tick-labels-from-axis/</link>
		<comments>http://scienceoss.com/change-distance-of-tick-labels-from-axis/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 15:42:01 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[plotting]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[axis]]></category>
		<category><![CDATA[pylab]]></category>
		<category><![CDATA[tick labels]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=63</guid>
		<description><![CDATA[Set the rc parameters using the rc function. import pylab as p p.rc(('xtick.major','xtick.minor','ytick.major','ytick.minor'), pad=10) p.plot([1,2,3]) If you only want to change one of the tick labels, say, the x major ticks, use p.rc(&#8216;xtick.major), pad=10) When you&#8217;re done and want to reset the rc settings, use p.rcdefaults() See matplotlibrc for more settings you can change via [...]]]></description>
			<content:encoded><![CDATA[<p>Set the rc parameters using the <span class="c">rc</span> function.</p>
<pre class = "prettyprint"><code class = "code">
import pylab as p
p.rc(('xtick.major','xtick.minor','ytick.major','ytick.minor'), pad=10)
p.plot([1,2,3])
</code></pre>
<p>If you only want to change one of the tick labels, say, the x major ticks, use<br />
p.rc(&#8216;xtick.major), pad=10)</p>
<p>When you&#8217;re done and want to reset the rc settings, use</p>
<pre class = "prettyprint"><code class = "code">p.rcdefaults()</code></pre>
<p>See matplotlibrc for more settings you can change via the <code>rc</code> command.</p>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/change-distance-of-tick-labels-from-axis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change tick locations and labels in ggplot</title>
		<link>http://scienceoss.com/change-tick-locations-and-labels-in-ggplot/</link>
		<comments>http://scienceoss.com/change-tick-locations-and-labels-in-ggplot/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 01:00:00 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[axis]]></category>
		<category><![CDATA[tick labels]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=61</guid>
		<description><![CDATA[Use the scale_x_continuous (or scale_y_continuous) to change tick locations and labels in ggplot. Change the ticks: p = ggplot(diamonds)+aes(x=carat,y=price) + scale_x_continuous(breaks=c(1,1.2,1.5,2.5)) Change the ticks and tick labels: p = ggplot(diamonds)+aes(x=carat,y=price) + scale_x_continuous(breaks=c(1,1.2,1.5,2.5), labels=c('a','b','c','d'))]]></description>
			<content:encoded><![CDATA[<p>Use the scale_x_continuous (or scale_y_continuous) to change tick locations and labels in <a href="http://had.co.nz/ggplot2/">ggplot</a>.</p>
<p>Change the ticks:</p>
<pre class = "prettyprint"><code class = "code">
p = ggplot(diamonds)+aes(x=carat,y=price) +
   scale_x_continuous(breaks=c(1,1.2,1.5,2.5))
</code></pre>
<p>Change the ticks and tick labels:</p>
<pre class = "prettyprint"><code class = "code">p = ggplot(diamonds)+aes(x=carat,y=price) +
   scale_x_continuous(breaks=c(1,1.2,1.5,2.5), labels=c('a','b','c','d'))</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/change-tick-locations-and-labels-in-ggplot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a second y-axis in matplotlib</title>
		<link>http://scienceoss.com/create-a-second-y-axis-in-matplotlib/</link>
		<comments>http://scienceoss.com/create-a-second-y-axis-in-matplotlib/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 16:48:36 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[matplotlib]]></category>
		<category><![CDATA[axis]]></category>
		<category><![CDATA[plot]]></category>
		<category><![CDATA[pylab]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[subplot]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=30</guid>
		<description><![CDATA[Today I was trying to figure out how to plot two time series with differently scaled values. I found two_scales.py example in the matplotlib examples which describes how to do it. Here&#8217;s a slightly simplified version of the code, and afterward a detailed explanation of what&#8217;s going on. from pylab import * x = [1,2,3,4,5] [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was trying to figure out how to plot two time series with differently scaled values.  I found  <a href="http://matplotlib.sourceforge.net/examples/two_scales.py">two_scales.py</a> example in the matplotlib examples which describes how to do it.</p>
<p>Here&#8217;s a slightly simplified version of the code, and afterward a detailed explanation of what&#8217;s going on.<span id="more-30"></span></p>
<pre class = "prettyprint"><code class = "code">
from pylab import *

x = [1,2,3,4,5]
y1 = [10,25,30,45,50]
y2 = [1,3,4,7,12]

ax1 = subplot(111)

plot(x, y1, 'b-')

ax2 = twinx()

plot(x, y2, 'r--')
show()</code></pre>
<h2>Step-by-step explanation.</h2>
<p>Basically, we make two separate axes right on top of each other.  The data in y1 will go on the first created axes, and y2 will go on the second created axes.  The key to this is the twinx() function.  What it does is explained below.<br />
<img style="border:1px dashed; padding:10px;float:left;margin:10px;" src='http://blog.anonrandomname.com/wp-content/uploads/2007/12/text3610.png' alt='two axes code explanation 01' /><br />
<br style="clear:both"/><br />
<img class="codeExample" src='http://blog.anonrandomname.com/wp-content/uploads/2007/12/two_axes1.png' alt='two axes code explanation 03' /><br />
<br style="clear:both;"/><br />
<img class="codeExample" src='http://blog.anonrandomname.com/wp-content/uploads/2007/12/two_axes2.png' alt='two axes code explanation 04' /><br />
What&#8217;s happening here? <span class="c">twinx()</span> duplicates the current set of axes (the current set of axes is ax1).  The source code of <span class="c">twinx()</span> has a line like this:</p>
<pre class="prettyprint"><code class = "code">ax2 = gcf().add_axes(ax1.get_position(), sharex=ax1, frameon=False)</code></pre>
<p>Which:</p>
<ul>
<li>adds a new set of axes to the current figure (that&#8217;s the <span class="c">gcf()</span> part).</li>
<li>puts the new set of axes in the same position as <span class="c">ax1</span> (that&#8217;s the <span class="c">ax1.get_position()</span> part)</li>
<li>makes the new set of axes have an x axis with the same properties as the first axes, <span class="c">ax1</span>.  When you pan or zoom the figure both axes will move together.</li>
<li>returns the new axis
</ul>
<p>The result is a new set of axes right on top of the old one, ready and primed for some plotting.</p>
<p>The rest of the code plots a red dashed line in the new axes using the data in <span class="c">y2</span>, and the <span class="c">show()</span> command shows your handiwork.<br />
*not really magic</p>
<h2>Final product</h2>
<p><a href='http://blog.anonrandomname.com/wp-content/uploads/2007/12/two-axes.png' title='two y axes example'><img src='http://blog.anonrandomname.com/wp-content/uploads/2007/12/two-axes.png' alt='two y axes example' /></a></p>
<h2>Oh no! I forgot to label the axes!</h2>
<p>The nice thing about saving the axes as ax1 and ax2 is that you can change either one of them at any time.  Just call any one of the 280 possibilities (In IPython, type ax1, then a &#8220;.&#8221;, then the tab key &#8212; that is, ax1.[TAB] &#8212; for a list of what axes can do).</p>
<p>For example, you can use the set_ylabel() method of each axes object.</p>
<pre class = "prettyprint"><code class = "code">
ax1.set_ylabel('first y-axis')
ax2.set_yabel('second y-axis')
</code></pre>
<p>If you have already used show(), then your changes WON&#8217;T immediately be updated.  This is by design, in case you are adding many things to a figure and don&#8217;t want to refresh after every little thing you add.  Once you&#8217;re ready to redraw the figure, Use</p>
<pre class = "prettyprint"><code class = "code">draw()</code></pre>
<p>You can label the x axis too, but you&#8217;ll only need to choose either <span class="c">ax1.set_xlabel(&#8216;x label here&#8217;)</span> or <span class="c">ax2.set_xlabel(&#8216;x label here&#8217;)</span>.  You can remove an axis label by just setting it to an empty string: ax2.set_xlabel(&#8221;).</p>
<p>With labels, it looks something like this:<br />
<img src='http://blog.anonrandomname.com/wp-content/uploads/2007/12/labeled-two-axes.png' alt='two y axes with axis labels' /></p>
<h2>More than two y-axes?</h2>
<p>Unfortunately, this is not yet implemented in matplotlib but it&#8217;s on the wishlist, as <a href="http://sourceforge.net/mailarchive/message.php?msg_id=42E2C619-976C-4E19-870B-5A590D44FC31%40llnl.gov">this post</a> describes, along with a suggestion to use PyX instead of matplotlib for a graph of this type.</p>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/create-a-second-y-axis-in-matplotlib/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

