Python
2014.04.28 15:57

pylab - Plotting with Matplotlib

조회 수 9802 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print

이곳 Doc를 참조할 것


http://matplotlib.org/api/pyplot_api.html




%pylab makes the following imports:

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot

from IPython.display import display
from IPython.core.pylabtools import figsize, getfigs

from pylab import *
from numpy import *






http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Notebook/Plotting%20with%20Matplotlib.ipynb



Plotting with Matplotlib

IPython works with the Matplotlib plotting library, which integrates Matplotlib with IPython's display system and event loop handling.

matplotlib mode

To make plots using Matplotlib, you must first enable IPython's matplotlib mode.

To do this, run the %matplotlib magic command to enable plotting in the current Notebook.

This magic takes an optional argument that specifies which Matplotlib backend should be used. Most of the time, in the Notebook, you will want to use the inline backend, which will embed plots inside the Notebook:

In [1]:
%matplotlib inline

You can also use Matplotlib GUI backends in the Notebook, such as the Qt backend (%matplotlib qt). This will use Matplotlib's interactive Qt UI in a floating window to the side of your browser. Of course, this only works if your browser is running on the same system as the Notebook Server. You can always call the display function to paste figures into the Notebook document.

Making a simple plot

With matplotlib enabled, plotting should just work.

In [2]:
import matplotlib.pyplot as plt
import numpy as np
In [3]:
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('A simple chirp');
x+3ghdT1LKwsgAAAABJRU5ErkJggg==

These images can be resized by dragging the handle in the lower right corner. Double clicking will return them to their original size.

One thing to be aware of is that by default, the Figure object is cleared at the end of each cell, so you will need to issue all plotting commands for a single figure in a single cell.

Loading Matplotlib demos with %load

IPython's %load magic can be used to load any Matplotlib demo by its URL:

In [4]:
%load http://matplotlib.org/mpl_examples/showcase/integral_demo.py
In [5]:
"""
Plot demonstrating the integral as the area under a curve.

Although this is a simple example, it demonstrates some important tweaks:

    * A simple line plot with custom color and line width.
    * A shaded region created using a Polygon patch.
    * A text label with mathtext rendering.
    * figtext calls to label the x- and y-axes.
    * Use of axis spines to hide the top and right spines.
    * Custom tick placement and labels.
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon


def func(x):
    return (x - 3) * (x - 5) * (x - 7) + 85


a, b = 2, 9 # integral limits
x = np.linspace(0, 10)
y = func(x)

fig, ax = plt.subplots()
plt.plot(x, y, 'r', linewidth=2)
plt.ylim(ymin=0)

# Make the shaded region
ix = np.linspace(a, b)
iy = func(ix)
verts = [(a, 0)] + list(zip(ix, iy)) + [(b, 0)]
poly = Polygon(verts, facecolor='0.9', edgecolor='0.5')
ax.add_patch(poly)

plt.text(0.5 * (a + b), 30, r"$\int_a^b f(x)\mathrm{d}x$",
         horizontalalignment='center', fontsize=20)

plt.figtext(0.9, 0.05, '$x$')
plt.figtext(0.1, 0.9, '$y$')

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')

ax.set_xticks((a, b))
ax.set_xticklabels(('$a$', '$b$'))
ax.set_yticks([])

plt.show()
IAAAAABJRU5ErkJggg==


Dreamy의 코드 스크랩

내가 모으고 내가 보는

List of Articles
번호 분류 제목 날짜 조회 수 추천 수
281 Android L버전 32/64bit tip 및 multi user 관련 adb 명령어 2014.11.18 8459 0
280 LINUX shell 에서 background로 명령어 수행하기 2014.11.11 37162 0
279 LINUX 리눅스에서 특정작업 or 명령어 반복하기 Crontab 2014.11.10 10349 0
278 LINUX [Shell Script] 쉘 스크립트에서 getopt 사용하는 법 2014.11.09 17000 0
277 LINUX [Shell Script] 쉘 스크립트에서의 사칙연산과 문자열 자르기 2014.11.01 81840 0
276 C# C# 배열 array 2014.10.22 12591 0
275 Android 에러 넘버 ErrorNo in Linux 2014.10.14 9419 0
274 일반 배치파일(bat)에서 날짜-시간을 파일 명으로 쓰기 2014.10.10 29293 0
273 Android logcat, main+kernel로그 합치는 로그 2014.10.07 10368 0
272 LINUX [Shell Script] 파일을 한줄씩 읽어오기 2014.10.03 56454 0
271 LINUX [Shell Script] Shell 스크립트에서 매개변수 치환 2014.09.23 29714 0
270 LINUX [Shell Script] 쉘 스크립트 개요 2014.09.23 28050 0
269 LINUX [Shell Script] 리눅스 쉘(Shell) 스크립트 2014.09.23 86908 0
268 LINUX [Shell Script] 글자 속성, 색깔 지정 2014.09.23 32254 0
267 Android tag 없이 repo sync 후 특정 tag 만 당겨오기 2014.09.18 11454 0
목록
Board Pagination ‹ Prev 1 ... 11 12 13 14 15 16 17 18 19 20 ... 34 Next ›
/ 34

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Designed by sketchbooks.co.kr / sketchbook5 board skin

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5