from matplotlib import pyplot as plt
'https://matplotlib.org/3.3.0/tutorials/introductory/pyplot.html#sphx-glr-tutorials-introductory-pyplot-py'
plt.plot([1,2,3,4],[1,4,9,16],linewidth=0,marker='X',c='060606')
plt.axis([0,6,0,20])
#plt.xlim([0,10])
plt.ylabel('some numbers')
plt.xlabel('eixo x')
plt.show()
import numpy as np
t = np.arange(0,5,.2)
plt.plot(t,t,'r--',t,t**3,'bs',t,t**(-1),'g^')
plt.show()
C:\Users\caiod\Anaconda3\lib\site-packages\ipykernel_launcher.py:4: RuntimeWarning: divide by zero encountered in reciprocal after removing the cwd from sys.path.
data = {'a':np.arange(50),
'c':np.random.randint(0,50,50),
'd': np.random.randn(50)}
data['b'] = data['a'] + 10* np.random.randn(50)
data['d'] = np.abs(data['d']) * 100
plt.scatter('a','b',c='c',s='d',data=data)
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()
names = ['group_a','group_b','group_c']
values = [1,10,100]
plt.figure(figsize=(9,3))
plt.subplot(131)
plt.bar(names,values)
plt.subplot(132)
plt.scatter(names,values)
plt.subplot(133)
plt.plot(names,values)
plt.suptitle('Categorical Plotting')
plt.show()
x=[1,2,3]
y=[1,2,3]
plt.plot(x,y,linewidth=20.0)
[<matplotlib.lines.Line2D at 0x272fbf9cf88>]
line,=plt.plot(x,y,'--')
line.set_antialiased(False)
x1 = [1,2,3,4,50]
y1 = [1,25,3,4,70]
x2 = [2,8,10,60]
y2 = [20,25,20,25]
lines = plt.plot(x1,y1,x2,y2)
plt.setp(lines[0],color='blue',linewidth = 2.0)
plt.setp(lines[1],color='orange',linewidth = 20.0)
#plt.setp(lines,'color','b','linewidth','2.0')
[None, None]
plt.setp(lines)
agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
alpha: float
animated: bool
antialiased or aa: bool
clip_box: `.Bbox`
clip_on: bool
clip_path: [(`~matplotlib.path.Path`, `.Transform`) | `.Patch` | None]
color or c: color
contains: callable
dash_capstyle: {'butt', 'round', 'projecting'}
dash_joinstyle: {'miter', 'round', 'bevel'}
dashes: sequence of floats (on/off ink in points) or (None, None)
drawstyle or ds: {'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'
figure: `.Figure`
fillstyle: {'full', 'left', 'right', 'bottom', 'top', 'none'}
gid: str
in_layout: bool
label: object
linestyle or ls: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
linewidth or lw: float
marker: marker style
markeredgecolor or mec: color
markeredgewidth or mew: float
markerfacecolor or mfc: color
markerfacecoloralt or mfcalt: color
markersize or ms: float
markevery: None or int or (int, int) or slice or List[int] or float or (float, float)
path_effects: `.AbstractPathEffect`
picker: float or callable[[Artist, Event], Tuple[bool, dict]]
pickradius: float
rasterized: bool or None
sketch_params: (scale: float, length: float, randomness: float)
snap: bool or None
solid_capstyle: {'butt', 'round', 'projecting'}
solid_joinstyle: {'miter', 'round', 'bevel'}
transform: `matplotlib.transforms.Transform`
url: str
visible: bool
xdata: 1D array
ydata: 1D array
zorder: float
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
t1 = np.arange(0,5,0.1)
t2 = np.arange(0,5,0.02)
plt.figure()
plt.subplot(211)
plt.plot(t1,f(t1),'bo',t2,f(t2),'k',)
plt.subplot(212)
plt.plot(t2,np.cos(2*np.pi*t2),'r--')
plt.show()
import matplotlib.pyplot as plt
plt.figure(1) # the first figure
plt.subplot(211) # the first subplot in the first figure
plt.plot([1, 2, 3])
plt.subplot(212) # the second subplot in the first figure
plt.plot([4, 5, 6])
plt.figure(2) # a second figure
plt.plot([4, 5, 6]) # creates a subplot(111) by default
plt.figure(1) # figure 1 current; subplot(212) still current
plt.subplot(211) # make subplot(211) in figure1 current
plt.title('Easy as 1, 2, 3') # subplot 211 title
C:\Users\caiod\Anaconda3\lib\site-packages\ipykernel_launcher.py:13: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance. del sys.path[0]
Text(0.5, 1.0, 'Easy as 1, 2, 3')
mu,sigma = 100,15
x = mu + sigma * np.random.randn(10000)
#the histogram of the data
n,bins,patches = plt.hist(x,50,density = 1,facecolor='g',alpha = 0.75)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of X')
plt.text(60, 0.025,r'$\mu=100,\ \sigma=15$')
plt.axis([40,160,0,0.03])
plt.grid(True)
t = plt.xlabel('MY DATA',fontsize=14,color='r')
plt.title(r'$\sigma_i=15$')
plt.show()
ax = plt.subplot(111)
t = np.arange(0.0,5.0,0.01)
s = np.cos(2*np.pi*t)
line, = plt.plot(t,s,lw=2)
plt.annotate('LOCAL MAX', xy = (2,1),xytext = (3,1.5),arrowprops = {'facecolor':'black','shrink':0.05},color='g',fontsize=20)
plt.axis([0,4,-1.2,1.2])
plt.show()
[0, 4, -1.2, 1.2]
# Fixing random state for reproducibility
np.random.seed(19680801)
# make up some data in the open interval (0, 1)
y = np.random.normal(loc=0.5, scale=0.4, size=1000)
y = y[(y > 0) & (y < 1)]
y.sort()
x = np.arange(len(y))
# plot with various axes scales
plt.figure()
# linear
plt.subplot(221)
plt.plot(x, y)
plt.yscale('linear')
plt.title('linear')
plt.grid(True)
# log
plt.subplot(222)
plt.plot(x, y)
plt.yscale('log')
plt.title('log')
plt.grid(True)
# symmetric log
plt.subplot(223)
plt.plot(x, y - y.mean())
plt.yscale('symlog', linthresh=0.01)
plt.title('symlog')
plt.grid(True)
# logit
plt.subplot(224)
plt.plot(x, y)
plt.yscale('logit')
plt.title('logit')
plt.grid(True)
# Adjust the subplot layout, because the logit one may take more space
# than usual, due to y-tick labels like "1 - 10^{-3}"
plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,
wspace=0.35)
plt.show()
np.random.seed(19680801)
dt = 0.001
t = np.arange(0.0,10.0,dt)
r = np.exp(-t[:1000] / 0.05)
x = np.random.randn(len(t))
s = np.convolve(x,r)[:len(x)] * dt
fig, main_ax = plt.subplots()
main_ax.plot(t,s)
main_ax.set_xlim(0, 1)
main_ax.set_ylim(1.1 * np.min(s), 2 * np.max(s))
main_ax.set_xlabel('time (s)')
main_ax.set_ylabel('current (nA)')
main_ax.set_title('Gaussian colored noise')
right_inset_ax = fig.add_axes([.65,.6,.2,.2],facecolor='cyan')
right_inset_ax.hist(s,400,density=True)
right_inset_ax.set(title='Probability',xticks=[],yticks = [])
left_inset_ax = fig.add_axes([.2,.6,.2,.2],facecolor='yellow')
left_inset_ax.plot(t[:len(r)],r)
left_inset_ax.set(title = 'Impulse response',xlim = (0,.2),xticks = [], yticks =[])
plt.show()
'https://matplotlib.org/3.3.0/gallery/subplots_axes_and_figures/axes_demo.html'