댓글 쓰기 권한이 없습니다. 로그인 하시겠습니까?
Python
2014.04.28 15:57
pylab - Plotting with Matplotlib
조회 수 11193 댓글 0
이곳 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 MatplotlibIPython works with the Matplotlib plotting library, which integrates Matplotlib with IPython's display system and event loop handling. matplotlib modeTo make plots using Matplotlib, you must first enable IPython's matplotlib mode. To do this, run the 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 In [1]: %matplotlib inline
You can also use Matplotlib GUI backends in the Notebook, such as the Qt backend ( Making a simple plotWith 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');
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 Loading Matplotlib demos with %loadIPython's 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()
Dreamy의 코드 스크랩내가 모으고 내가 보는
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Designed by sketchbooks.co.kr / sketchbook5 board skin
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5
Sketchbook5, 스케치북5