In [1]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-4, 4, 1024)
Y = .25 * (X + 4.) * (X + 1.) * (X - 2.)

plot.title('A polynomial')
plot.plot(X, Y, c = 'k')
plot.show()



In [2]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-4, 4, 1024)
Y = .25 * (X + 4.) * (X + 1.) * (X - 2.)

plot.title('Power curve for airfoil KV873')
plot.xlabel('Air speed')
plot.ylabel('Total drag')

plot.plot(X, Y, c = 'k')
plot.show()



In [12]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-4, 4, 1024)
Y = .25 * (X + 4.) * (X + 1.) * (X - 2.)

plot.text(-1.5, 5, 'Brackmard minimum', ha='right')

plot.plot(X, Y, c = 'k')
plot.show()



In [10]:
import matplotlib.pyplot as plot

align_list = ('center', 'left', 'right')

ax1 = plot.axes()
ax1.axes.get_xaxis().set_visible(False)
ax1.axes.get_yaxis().set_visible(False)

for i, align in enumerate(align_list):
	plot.text(0, i, 'align=\'%s\'' % align, ha = align)

plot.plot([0, 0], [-1, len(align_list)], c = '#808080', ls = '--')
plot.scatter([0] * len(align_list), range(len(align_list)))

plot.show()



In [13]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-4, 4, 1024)
Y = .25 * (X + 4.) * (X + 1.) * (X - 2.)

box = {
	'facecolor' : '.75',#상자색깔
	'edgecolor' : 'k',
  'boxstyle'  : 'round'
}

plot.text(-0.5, -0.20, 'Brackmard minimum', bbox = box)

plot.plot(X, Y, c = 'k')
plot.show()



In [271]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-4, 4, 1024)
Y = .25 * (X + 4.) * (X + 1.) * (X - 2.)

plot.annotate('Brackmard minimum',
              ha = 'center', va = 'bottom',
              xytext = (-1.5, 3.),
              xy = (2.5, -2.7),
              arrowprops = { 'facecolor' : 'k', 'shrink' : 0.05, style ='<' }
             )

plot.plot(X, Y, c = 'k' )
plot.show()


  File "<ipython-input-271-56cc0fb31a53>", line 11
    arrowprops = { 'facecolor' : 'k', 'shrink' : 0.05, style ='<' }
                                                             ^
SyntaxError: invalid syntax

In [35]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(0, 6, 1024)
Y1 = numpy.sin(X)
Y2 = numpy.cos(X)

plot.xlabel('X')
plot.ylabel('Y')

plot.plot(X, Y1, c = 'k',             lw = 3., label = 'sin(X)')
plot.plot(X, Y2, c = '.5', ls = '--', lw = 3., label = 'cos(X)')

plot.legend(loc=9)
plot.grid(ls='--')
plot.show()



In [36]:
import matplotlib.pyplot as plot

shape = plot.Circle((0, 0), radius = 1., color = '#8080f0')
plot.gca().add_patch(shape)

plot.grid(True)
plot.axis('scaled')
plot.show()



In [37]:
import matplotlib.patches as patches
import matplotlib.pyplot as plot

# Circle
shape = patches.Circle((0, 0), radius = 1., color = '.75')
plot.gca().add_patch(shape)

# Rectangle
shape = patches.Rectangle((2.5, -.5), 2., 1., color = '.75')
plot.gca().add_patch(shape)

# Ellipse
shape = patches.Ellipse((0, -2.), 2., 1., angle = 45., color = '.75')
plot.gca().add_patch(shape)

# Fancy box
shape = patches.FancyBboxPatch((2.5, -2.5), 2., 1., boxstyle = 'sawtooth', color = '.75')
plot.gca().add_patch(shape)

# Display all
plot.grid(True)
plot.axis('scaled')
plot.show()



In [38]:
import matplotlib.pyplot as plot

N = 16
for i in range(N):
	plot.gca().add_line(plot.Line2D((0, i), (N - i, 0), color = '.5'))

plot.grid(True)
plot.axis('scaled')
plot.show()



In [39]:
import numpy
import matplotlib.pyplot as plot

theta = numpy.linspace(0, 2 * numpy.pi, 8)
points = numpy.vstack((numpy.cos(theta), numpy.sin(theta))).transpose()

plot.gca().add_patch(plot.Polygon(points, color = '.75'))

plot.grid(True)
plot.axis('scaled')
plot.show()



In [277]:
import numpy
import matplotlib.pyplot as plot
import matplotlib.ticker as ticker

X = numpy.linspace(-15, 15, 1024)
Y = numpy.sinc(X)

ax = plot.axes()
ax.xaxis.set_major_locator(ticker.MultipleLocator(6))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))
plot.grid()
#plot.grid(True, which='both')
plot.plot(X, Y, c = 'k')
plot.show()



In [45]:
import numpy
import matplotlib.ticker as ticker
import matplotlib.pyplot as plot

name_list = ('Omar', 'Serguey', 'Max', 'Zhou', 'Abidin')
value_list = numpy.random.randint(0, 99, size = len(name_list))
pos_list = numpy.arange(len(name_list))

ax = plot.axes()
ax.xaxis.set_major_locator(ticker.FixedLocator((pos_list)))
ax.xaxis.set_major_formatter(ticker.FixedFormatter((name_list)))

plot.bar(pos_list, value_list, color = '.75', align = 'center')

plot.show()



In [289]:
import numpy
import matplotlib.pyplot as plot
name_list = ('Omar', 'Serguey', 'Max', 'Zhou', 'Abidin')
value_list = numpy.random.randint(0, 99, size = len(name_list))
pos_list = numpy.arange(len(name_list))

plot.bar(pos_list, value_list, color = '.75', align = 'center')

plot.xticks(pos_list, name_list)

plot.show()



In [49]:
import numpy
import matplotlib.pyplot as plot
import matplotlib.ticker as ticker

def make_label(value, pos):
	return '%0.1f%%' % (100. * value)

ax = plot.axes()
ax.xaxis.set_major_formatter(ticker.FuncFormatter(make_label))

X = numpy.linspace(0, 1, 256)
plot.plot(X, numpy.exp(-10 * X), c = 'k')
plot.plot(X, numpy.exp(-5 * X), c = 'k', ls = '--')

plot.show()



In [91]:
import numpy, datetime
import matplotlib.pyplot as plot
import matplotlib.dates as dates
import matplotlib.ticker as ticker

start_date = datetime.datetime(1998, 1, 1)

def make_label(value, pos):
	time = start_date + datetime.timedelta(days = 365 * value)
	return time.strftime('%b %y')

ax = plot.axes()
ax.xaxis.set_major_formatter(ticker.FuncFormatter(make_label))

X = numpy.linspace(0, 1, 256)
plot.plot(X, numpy.exp(-10 * X), c = 'k')
plot.plot(X, numpy.exp(-5 * X), c = 'k', ls = '--')

labels = ax.get_xticklabels()
plot.setp(labels, rotation = 30.)

plot.show()



In [126]:
import numpy
from matplotlib import pyplot as plot

T = numpy.linspace(-numpy.pi, numpy.pi, 1024)

grid_size = (4, 2)

plot.subplot2grid(grid_size, (0, 0), rowspan=3, colspan=1)
plot.plot(numpy.sin(2 * T), numpy.cos(0.5 * T), c= 'k')

plot.subplot2grid(grid_size, (0, 1), rowspan=3, colspan=1)
plot.plot(numpy.cos(3 * T), numpy.sin(T), c= 'k')

plot.subplot2grid(grid_size, (3, 0), rowspan=1, colspan=2)
plot.plot(numpy.cos(5 * T), numpy.sin(7 * T), c= 'k')

plot.tight_layout()
plot.show()



In [127]:
import numpy
from matplotlib import pyplot as plot

def get_radius(T, params):
	m, n_1, n_2, n_3 = params
	U = (m * T) / 4
	return (numpy.fabs(numpy.cos(U)) ** n_2 + numpy.fabs(numpy.sin(U)) ** n_3) ** (-1. / n_1)

grid_size = (3, 4)
T = numpy.linspace(0, 2 * numpy.pi, 1024)

for i in range(grid_size[0]):
	for j in range(grid_size[1]):
		params = numpy.random.random_integers(1, 20, size = 4)
		R = get_radius(T, params)

		axes = plot.subplot2grid(grid_size, (i, j), rowspan=1, colspan=1)
		axes.get_xaxis().set_visible(False)
		axes.get_yaxis().set_visible(False)
		plot.plot(R * numpy.cos(T), R * numpy.sin(T), c = 'k')

		plot.title('%d, %d, %d, %d' % tuple(params), fontsize = 'small')

plot.tight_layout()
plot.show()


c:\users\gin22\miniconda3\envs\ml_python\lib\site-packages\ipykernel_launcher.py:14: DeprecationWarning: This function is deprecated. Please call randint(1, 20 + 1) instead
  

In [184]:
import numpy
import matplotlib.pyplot as plot

T = numpy.linspace(-numpy.pi, numpy.pi, 1024)

plot.plot(2. * numpy.cos(T), numpy.sin(T), c = 'k', lw = 3.)
#plot.axes().set_aspect('equal')

plot.show()



In [167]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-6, 6, 1024)

plot.ylim(-.5, 1.5)#y범위 설정
plot.plot(X, numpy.sinc(X), c = 'k')

plot.show()



In [178]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-6, 6, 1024)
Y1, Y2 = numpy.sinc(X), numpy.cos(X)

fig = plot.figure(figsize=(12, 5))

plot.ylim(-0.5 * numpy.pi, 0.5 * numpy.pi)

plot.plot(X, Y1, c='k', lw = 3.)
plot.plot(X, Y2, c='.75', lw = 3.)
plot.show()



In [294]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(1, 10, 1024)

plot.yscale('log', basey=2)

plot.plot(X, X, c = 'k', lw = 2., label = r'$f(x)=x$')
plot.plot(X, 10 ** X, c = '.75', ls = '--', lw = 2., label = r'$f(x)=e^x$')
plot.plot(X, numpy.log(X), c = '.75', lw = 2., label = r'$f(x)=\log(x)$')

plot.legend()
plot.show()



In [243]:
import numpy
import matplotlib.pyplot as plot

X = numpy.linspace(-100, 100, 4096)

plot.xscale('symlog', linthreshx=6.)

plot.plot(X, numpy.sinc(X), c = 'k')
plot.show()



In [204]:
import numpy
import matplotlib.pyplot as plot

T = numpy.linspace(0 , 2 * numpy.pi, 1024)

plot.axes(polar = True)
plot.plot(T, 10. + .20 * numpy.sin(50 * T), c = 'k')

plot.show()



In [228]:
import numpy
import matplotlib.patches as patches
import matplotlib.pyplot as plot

ax = plot.axes(polar = True)

theta = numpy.linspace(0, 2 * numpy.pi, 8, endpoint = False)
radius = .25 + .75 * numpy.random.random(size = len(theta))
points = list(zip(theta, radius))

plot.gca().add_patch(patches.Polygon(points, color = '.75'))

plot.show()



In [290]:
import numpy
from matplotlib import pyplot as plot


X = numpy.linspace(-6, 6, 1024)
plot.plot(X, numpy.sinc(X), c = 'k')

a = plot.axes([.6, .6, .25, .25])
X = numpy.linspace(-3, 3, 1024)
a.plot(X, numpy.sinc(X), c = 'k')
plot.setp(a)

plot.show()


  adjustable: [ 'box' | 'datalim' | 'box-forced'] 
  agg_filter: unknown
  alpha: float (0.0 transparent through 1.0 opaque) 
  anchor: unknown
  animated: [True | False] 
  aspect: unknown
  autoscale_on: unknown
  autoscalex_on: unknown
  autoscaley_on: unknown
  axes: an :class:`~matplotlib.axes.Axes` instance 
  axes_locator: unknown
  axisbelow: [ *True* | *False* | 'line' ] 
  clip_box: a :class:`matplotlib.transforms.Bbox` instance 
  clip_on: [True | False] 
  clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ] 
  color_cycle: unknown
  contains: a callable function 
  facecolor: unknown
  fc: unknown
  figure: unknown
  frame_on: [ *True* | *False* ] 
  gid: an id string 
  label: string or anything printable with '%s' conversion. 
  navigate: [ *True* | *False* ] 
  navigate_mode: unknown
  path_effects: unknown
  picker: [None|float|boolean|callable] 
  position: unknown
  rasterization_zorder: unknown
  rasterized: [True | False | None] 
  sketch_params: unknown
  snap: unknown
  title: unknown
  transform: :class:`~matplotlib.transforms.Transform` instance 
  url: a url string 
  visible: [True | False] 
  xbound: unknown
  xlabel: unknown
  xlim: unknown
  xmargin: unknown
  xscale: ['linear' | 'log' | 'logit' | 'symlog']
  xticklabels: sequence of strings
  xticks: sequence of floats 
  ybound: unknown
  ylabel: unknown
  ylim: unknown
  ymargin: unknown
  yscale: ['linear' | 'log' | 'logit' | 'symlog']
  yticklabels: sequence of strings
  yticks: sequence of floats
  zorder: any number 

In [232]:
import numpy
from matplotlib import pyplot as plot

X = numpy.linspace(-6, 6, 1024)
plot.plot(X, numpy.sinc(X))
plot.xticks([])
plot.yticks([])
plot.show()



In [246]:
import numpy
from matplotlib import pyplot as plot

X = numpy.linspace(-10, 10, 1024)
Y = numpy.sinc(X)

plot.plot(X, Y, c = 'k')
plot.savefig('sinc1.png')

In [261]:
import numpy
from matplotlib import pyplot as plot

X = numpy.linspace(-10, 10, 1024)
Y = numpy.sinc(X)

fig = plot.figure(figsize = (2.40, 1.80))
plot.plot(X, Y)
plot.savefig('sinc.png', dpi = 72)

In [262]:
import numpy
from matplotlib import pyplot as plot

X = numpy.linspace(-10, 10, 1024)
Y = numpy.sinc(X)

fig = plot.figure(figsize = (33.11, 46.81))
plot.plot(X, Y)
plot.savefig('sinc.pdf')

In [270]:
import numpy
 
from matplotlib import pyplot as plot
from matplotlib.backends.backend_pdf import PdfPages
 
# Generate the data
data = numpy.random.randn(15, 1024)

# The PDF document
pdf_pages = PdfPages('histograms.pdf')
 
# Generate the pages
nb_plots = data.shape[0]

nb_plots_per_page = 5
nb_pages = int(numpy.ceil(nb_plots / float(nb_plots_per_page)))
grid_size = (nb_plots_per_page, 1)
 
for i, samples in enumerate(data):
  # Create a figure instance (ie. a new page) if needed
  if i % nb_plots_per_page == 0:
  	fig = plot.figure(figsize=(8.27, 11.69), dpi=100)
 
  # Plot stuffs !
  plot.subplot2grid(grid_size, (i % nb_plots_per_page, 0))
  plot.hist(samples, 32, normed=1, facecolor='#808080', alpha=0.75)
 
  # Close the page if needed
  if (i + 1) % nb_plots_per_page == 0 or (i + 1) == nb_plots:
    plot.tight_layout()
    pdf_pages.savefig(fig)
 
# Write the PDF document to the disk
pdf_pages.close()


15
c:\users\gin22\miniconda3\envs\ml_python\lib\site-packages\matplotlib\pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: