In [1]:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
In [2]:
def listAttr(name, s = None):
if not s:
return [item for item in dir(name) if not item.startswith("_")]
return [item for item in dir(name) if (not item.startswith("_")) and s.lower() in item.lower()]
pass
In [5]:
plt.plot([1, 2, 3, 4])
plt.show()
In [6]:
plt.plot([1, 2, 3, 4], [1, 2, 3, 4])
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()
In [7]:
plt.plot([1, 2, 3, 4], [2, 5, 6, 4])
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()
In [8]:
plt.plot([1, 2, 3, 4], [2, 5, 6, 4])
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.axis([0, 5, 0, 10])
plt.show()
In [9]:
x = np.arange(1, 10)
y = x ** 2
y1 = 100 / x
y2 = x ** 2 - x
In [10]:
print(x)
print()
print(y)
print()
print(y1)
print()
print(y2)
In [11]:
plt.xlabel('Intergers')
plt.ylabel('Square')
plt.plot(x, y, y1) #(x, y) and (x,y1) graph
Out[11]:
In [12]:
plt.xlabel('Intergers')
plt.ylabel('Square')
#plt.plot(x, y, y1) #(x, y) and (x,y1) graph
plt.plot(x, y)
plt.plot(x, y1)
Out[12]:
In [13]:
plt.xlabel('Intergers')
plt.ylabel('Square')
plt.axis([0, 10, 0, 100]) #[xmin, xmax, ymin, ymax]
#plt.plot(x, y, x, y1, x, y2) #(x, y), (x,y1) and (x,y2) graph
plt.plot(x,y)
plt.plot(x,y1)
plt.plot(x,y2)
Out[13]:
In [14]:
# r = red, o = circle circle, default is line
plt.plot(x, y, y1, 'or') #(x,y) as red circle, (x,y1) as default
plt.axis([0, 10, 0, 100]) #[xmin, xmax, ymin, ymax]
plt.show()
In [15]:
plt.plot(x, y, 'r--', x, y1, 'bs', x, y2, 'g^')
plt.show()
In [16]:
plt.plot(x, y, 'r--')
plt.plot(x, y1, 'bs')
plt.plot(x, y2, 'g^')
plt.show()
In [17]:
#help(np.random.randint)
In [18]:
np.random.randint(0,5, 2)
Out[18]:
In [19]:
d1 = np.random.randn(50)
d1
Out[19]:
In [20]:
np.abs(d1)
Out[20]:
In [21]:
data = {
'a' : np.arange(50),
'b': np.random.randint(0,255, 50),
'd': np.random.randn(50)
}
In [22]:
data = {'a': np.arange(50),
'c': np.random.randint(0,255, 50),
'd': np.random.randn(50)
}
data['b'] = data['a'] + 10 * np.random.randn(50)
data['d'] = np.abs(data['d']) * 100
In [23]:
print(data["a"])
In [24]:
print(data["b"])
In [25]:
print(data["c"])
In [26]:
print(data["d"])
In [27]:
#print(data["a"])
print(data.keys())
print(data.values())
In [28]:
plt.xlabel('Intergers')
plt.ylabel('Square')
plt.plot(data['a'], data['b'], 'bo')
Out[28]:
In [29]:
plt.xlabel('Intergers')
plt.ylabel('Square')
plt.plot(data['b'], data['c'],'r--', data['a'],data['c'], 'bs')
Out[29]:
In [30]:
#help(plt.plot)
In [31]:
plt.plot('a','b','c' , data=data) # x= data['a'], y = data['b']
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()
In [32]:
print(data['b'])
In [33]:
print(data['a'])
In [34]:
plt.plot('a','b','c', data=data) # x= data['a'], y = data['b']
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()
In [35]:
#listAttr(plt)
In [36]:
#help(plt.scatter)
In [37]:
plt.scatter?
In [38]:
plt.scatter('a','b', data=data)
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()
In [39]:
plt.scatter('a','b', data=data)
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()
In [40]:
print(data['c'])
In [41]:
plt.scatter('a', 'b', c='c', data=data) # x= data['a'], y = data['b']
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()
In [42]:
print(data['d'])
In [43]:
plt.scatter('a', 'b', c='c', s='d', data=data) # x= data['a'], y = data['b']
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()