In [5]:
%matplotlib inline
In [8]:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(15,10))
ax = fig.add_subplot(111)
## the data
N = 5
menMeans = [18, 35, 30, 35, 27]
menStd = [2, 3, 4, 1, 2]
womenMeans = [25, 32, 34, 20, 25]
womenStd = [3, 5, 2, 3, 3]
## necessary variables
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
## the bars
rects1 = ax.bar(ind, menMeans, width,
color='black',
yerr=menStd,
error_kw=dict(elinewidth=2,ecolor='red'))
rects2 = ax.bar(ind+width, womenMeans, width,
color='red',
yerr=womenStd,
error_kw=dict(elinewidth=2,ecolor='black'))
# axes and labels
ax.set_xlim(-width,len(ind)+width)
ax.set_ylim(0,45)
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
xTickMarks = ['Group'+str(i) for i in range(1,6)]
ax.set_xticks(ind+width)
xtickNames = ax.set_xticklabels(xTickMarks)
plt.setp(xtickNames, rotation=45, fontsize=10)
## add a legend
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
plt.show()
In [19]:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(15,7))
ax1 = fig.add_subplot(121)
## the data
N=1000
x = np.random.randn(N)
y = np.random.randn(N)
## left panel
ax1.scatter(x,y,color='blue',s=5,edgecolor='none')
ax1.set_aspect(1./ax1.get_data_ratio()) # make axes square
## right panel
ax2 = fig.add_subplot(122)
props = dict(alpha=0.5, edgecolors='none' )
handles = []
colors = ['blue', 'green', 'magenta', 'cyan']
for color in colors:
x = np.random.randn(N)
y = np.random.randn(N)
s = np.random.randint(50,200)
handles.append(ax2.scatter(x, y, c=color, s=s, **props))
ax2.set_ylim([-5,11])
ax2.set_xlim([-5,11])
ax2.legend(handles, colors)
ax2.grid(True)
ax2.set_aspect(1./ax2.get_data_ratio())
plt.show()
In [18]:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(15,10))
ax = fig.add_subplot(111)
x = np.random.normal(0,1,1000)
numBins = 50
ax.hist(x,numBins,color='green',alpha=0.8)
plt.show()
numpy.random
zawiera wiele różnych rozkładów prawdopodobieństwa (histogram z przykładu to rozkład normalny). Proszę wybrać trzy dowolne rozkłady inne od normalnego i przedstawić ich histogramy. Histogramy powinny być umieszczone obok siebie. Proszę wybrać różne style i dodać odpowiednią legendę. Liczba przedziałów to 100.