Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Python

Log plots in Matplotlib

1
2
3
4
5
6
7
from pylab import *
fig = figure()
ax = fig.add_subplot(1,1,1)

#changes x oy y axis to logscale
ax.set_xscale('log')
ax.set_yscale('log')
https://snipt.net/embed/67807134d08e59dd7d9599fa1f3bee67/
https://snipt.net/raw/67807134d08e59dd7d9599fa1f3bee67/
67807134d08e59dd7d9599fa1f3bee67
python
Python
7
2016-12-10T07:40:37
True
False
False
Dec 06, 2012 at 09:22 AM
/api/public/snipt/51343/
log-plots-in-matplotlib
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">from</span> <span class="nn">pylab</span> <span class="kn">import</span> <span class="o">*</span> </span><span id="L-2"><a name="L-2"></a><span class="n">fig</span> <span class="o">=</span> <span class="n">figure</span><span class="p">()</span> </span><span id="L-3"><a name="L-3"></a><span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="c1">#changes x oy y axis to logscale</span> </span><span id="L-6"><a name="L-6"></a><span class="n">ax</span><span class="o">.</span><span class="n">set_xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span> </span><span id="L-7"><a name="L-7"></a><span class="n">ax</span><span class="o">.</span><span class="n">set_yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
Matplotlib, Python, axis, log, logscale

Python

Legend with only one marker in Matplotlib

1
2
3
4
5
#for markers
legend(numpoints = 1)

#for scatter
legend(scatterpoints = 1)
https://snipt.net/embed/9cab831021c7af9ee84da1b6750a231a/
https://snipt.net/raw/9cab831021c7af9ee84da1b6750a231a/
9cab831021c7af9ee84da1b6750a231a
python
Python
5
2016-12-10T07:40:53
True
False
False
/api/public/snipt/50698/
legend-with-only-one-marker-in-matplotlib
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">#for markers</span> </span><span id="L-2"><a name="L-2"></a><span class="n">legend</span><span class="p">(</span><span class="n">numpoints</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1">#for scatter</span> </span><span id="L-5"><a name="L-5"></a><span class="n">legend</span><span class="p">(</span><span class="n">scatterpoints</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span> </span></pre></div> </td></tr></table>
Matplotlib, legend, scatter

Python

Hide axis ticks and labels in Matplotlib

1
2
3
4
5
ax.set_xticklabels([])
ax.set_yticklabels([])

ax.set_xticks([])
ax.set_yticks([])
https://snipt.net/embed/9df107414900dc35b90623acea14fd30/
https://snipt.net/raw/9df107414900dc35b90623acea14fd30/
9df107414900dc35b90623acea14fd30
python
Python
5
2016-12-10T07:41:36
True
False
False
Nov 24, 2012 at 03:43 AM
/api/public/snipt/50696/
hide-axis-ticks-and-labels-in-matplotlib
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">ax</span><span class="o">.</span><span class="n">set_xticklabels</span><span class="p">([])</span> </span><span id="L-2"><a name="L-2"></a><span class="n">ax</span><span class="o">.</span><span class="n">set_yticklabels</span><span class="p">([])</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="n">ax</span><span class="o">.</span><span class="n">set_xticks</span><span class="p">([])</span> </span><span id="L-5"><a name="L-5"></a><span class="n">ax</span><span class="o">.</span><span class="n">set_yticks</span><span class="p">([])</span> </span></pre></div> </td></tr></table>
"hide axis ticks and labels", Matplotlib, Python, hide, labels, ticks

Python

Plot format defaults in Matplotlib

1
2
3
4
rc('font', family='serif')
rc('font', serif='Times New Roman')
rc('font', size=20)
rc('lines', linewidth=2)
https://snipt.net/embed/7cd75e7b22bd620b5f76c2768ad063a0/
https://snipt.net/raw/7cd75e7b22bd620b5f76c2768ad063a0/
7cd75e7b22bd620b5f76c2768ad063a0
python
Python
4
2016-12-09T17:48:00
True
False
False
Nov 20, 2012 at 01:57 PM
/api/public/snipt/50528/
plot-format-defaults-in-matplotlib
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">rc</span><span class="p">(</span><span class="s1">&#39;font&#39;</span><span class="p">,</span> <span class="n">family</span><span class="o">=</span><span class="s1">&#39;serif&#39;</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="n">rc</span><span class="p">(</span><span class="s1">&#39;font&#39;</span><span class="p">,</span> <span class="n">serif</span><span class="o">=</span><span class="s1">&#39;Times New Roman&#39;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="n">rc</span><span class="p">(</span><span class="s1">&#39;font&#39;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="n">rc</span><span class="p">(</span><span class="s1">&#39;lines&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span> </span></pre></div> </td></tr></table>
"plot format default", Matplotlib, Python, default, format, plot

Python

Hide axis in Matplolib

ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
https://snipt.net/embed/63647cd686e91f067adbbb65647844a3/
https://snipt.net/raw/63647cd686e91f067adbbb65647844a3/
63647cd686e91f067adbbb65647844a3
python
Python
2
2016-12-08T08:09:22
True
False
False
Nov 20, 2012 at 01:53 PM
/api/public/snipt/50527/
hide-axis-in-matplolib
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">ax</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">get_xaxis</span><span class="p">()</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="n">ax</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">get_yaxis</span><span class="p">()</span><span class="o">.</span><span class="n">set_visible</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span> </span></pre></div> </td></tr></table>
"hide axis", Matplotlib, Python, axis

Python

Fancy annotation in Matplotlib

1
2
3
annotate(r'$Math Text$',(x,y),
			fontsize=14,va='center',ha='center',color='b',
			bbox = dict(boxstyle="round", color='w',ec="0.5", alpha=1))
https://snipt.net/embed/aa3a5310f616300a4c287ef839294385/
https://snipt.net/raw/aa3a5310f616300a4c287ef839294385/
aa3a5310f616300a4c287ef839294385
python
Python
3
2016-12-08T08:09:37
True
False
False
/api/public/snipt/50526/
fancy-annotation-in-matplotlib
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">annotate</span><span class="p">(</span><span class="s1">r&#39;$Math Text$&#39;</span><span class="p">,(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">),</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">va</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span><span class="n">ha</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="n">bbox</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">boxstyle</span><span class="o">=</span><span class="s2">&quot;round&quot;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">,</span><span class="n">ec</span><span class="o">=</span><span class="s2">&quot;0.5&quot;</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span> </span></pre></div> </td></tr></table>
"rounded box", Matplotlib, Python, annotation
Copyrighted, illegal, or inappropriate content? Email [email protected].