import numpy as np
import pandas as pd
import sklearn.datasets as d
import seaborn as sns
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
from matplotlib.ticker import NullLocator, FixedLocator, LogLocator, MultipleLocator
%matplotlib inline
plt.plot([3, 7, 8]);
plt.plot([0, 1, 2], [3, 7, 8]);
#jakaś "ładna" funkcja
def f(x):
return np.pi*np.sin(x) + np.pi*np.cos(np.pi * x) + np.sin(x + np.pi)
x = np.linspace(0, 10, 100) # generuje 100 punktów między 0 i 10
y = f(x)
plt.plot(x, y);
for color in ['r', 'g', 'b', 'c', 'm']:
plt.plot(x, y, color=color) #parametr "color" lub skrócona wersja "c". Możesz sprawdzić, podając `c=color`.
plt.show()
for line_style in ['-', '-.', '--', ':', '']: #pusty string oznacza "żaden"
plt.plot(x, y, linestyle=line_style) #parameter "linestyle" lub skrócona wersja "ls"
plt.show()
all_markers = {'.': 'point',',': 'pixel','o': 'circle','v': 'triangle_down','^': 'triangle_up','<': 'triangle_left','>': 'triangle_right','1': 'tri_down','2': 'tri_up','3': 'tri_left','4': 'tri_right','8': 'octagon','s': 'square','p': 'pentagon','*': 'star','h': 'hexagon1','H': 'hexagon2','+': 'plus','x': 'x','D': 'diamond','d': 'thin_diamond','|': 'vline','_': 'hline'}
markers = {'.': 'point', 'o': 'circle', 's': 'square', '*': 'star','h': 'hexagon1'}
for marker, marker_name in markers.items():
print("{0}\t{1}".format(marker, marker_name))
plt.figure(figsize=(12, 7))
plt.plot(x, y, markersize=7, marker=marker)
plt.show()
locators = [
NullLocator(), #brak
FixedLocator([0, 1, 8]), #zafiksowany, będzie tylko dla 0, 1 i 8
LogLocator(2, [1.]), #skala logarytmiczna
MultipleLocator(3.) #co trzeci
]
for locator in locators:
print(str(locator))
plt.figure(figsize=(12, 7))
ax = plt.gca()
ax.xaxis.set_major_locator(locator)
plt.plot(x, y)
plt.show()
z = y / 4.0
plt.figure(figsize=(12, 7))
plt.plot(x, y, label="high")
plt.plot(x, z, label="low")
#dodanie legendy
plt.legend(loc='best'); #opcja "best" (można też wpisać po prostu 0) oznacza, że biblioteka samodzielnie poszukuje najlepszej możliwej opcji
plt.figure(figsize=(12, 7))
plt.plot(x, y, label="high")
plt.plot(x, z, label="low")
plt.ylim(-6, 7)
plt.annotate(r'$\pi sin(x) + \pi cos(\pi x) + \pi sin(x + \pi )$',
xy=(2, 5), xycoords='data',
xytext=(+3, +5.5), textcoords='data', fontsize=15,
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=.2"),
)
plt.plot([0, 10], [0, 0], color='grey', linestyle='-.')
plt.plot([2, 2],[0, 10], color='blue', linewidth=1, linestyle="--");
plt.figure(figsize=(12, 7))
plt.plot(x, y, label="high", marker='*')
plt.plot(x, z, label="low", marker='+')
plt.ylim(-6, 7)
plt.annotate(r'$\pi sin(x) + \pi cos(\pi x) + \pi sin(x + \pi )$',
xy=(2, 5), xycoords='data',
xytext=(+3, +5.5), textcoords='data', fontsize=15,
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=.2"),
)
plt.plot([0, 10], [0, 0], color='grey', linestyle='-.')
plt.plot([2, 2],[0, 10], color='blue', linewidth=1, linestyle="--")
plt.title("Magic Sinusoida", fontsize=20)
plt.xticks([0, np.pi, 2*np.pi, 3*np.pi],
[r'$0$', r'$+\pi$', r'$+2\pi$', r'$+3\pi$'])
plt.yticks([-6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6], [r'$-6$', r'$-5$', r'$-4$', r'$-3$', r'$-2$', r'$-1$', r'$0$', r'$+1$', r'$+2$', r'$+3$', r'$+4$', r'$+5$', r'$+6$'])
plt.legend(loc='best');
df = pd.read_csv('../input/load_test.csv') #wczytujemy dane
df.head()
## YOUR CODE IS HERE
#może przyda się, jeśli ciężko będzie poradzić z odstępami :)
#plt.ylim(0, 100)
#plt.xlim(0, 3000)
plt.figure(figsize=(12, 7))
plt.hist(np.random.randn(1000), bins=40);
plt.figure(figsize=(12, 7))
plt.boxplot(np.random.randn(50));
n = 100
plt.scatter(range(n), np.random.randn(n));
iris = d.load_iris()
print(iris.DESCR)
plt.figure(figsize=(12, 7))
plt.boxplot(iris.data)
plt.xticks(range(1, len(iris.data[0]) + 1), ['sepal length', 'sepal width', 'petal length', 'petal width'] )
plt.ylim(-1, 9);
sns.distplot(np.random.randn(1000));
sns.distplot(np.random.randn(1000), bins=100);
sns.distplot(np.random.randn(1000), hist=False);
sns.distplot(np.random.randn(1000), hist=False, rug=True);
iris = sns.load_dataset("iris")
sns.jointplot(x="sepal_length", y="sepal_width", data=iris, height=5);
sns.FacetGrid(iris, hue="species", height=5) \
.map(plt.scatter, "sepal_length", "sepal_width") \
.add_legend();
sns.boxplot(x="species", y="petal_length", data=iris);
sns.boxplot(x="species", y="petal_length", data=iris);
sns.stripplot(x="species", y="petal_length", jitter=True, data=iris);
sns.swarmplot(x="species", y="petal_length", data=iris);
melt_iris = pd.melt(iris, "species", var_name="measurement")
sns.boxplot(x="measurement", y="value", hue="species", data=melt_iris);
sns.swarmplot(x="measurement", y="value", hue="species", data=melt_iris);
sns.pairplot(iris, hue="species");
cmaps = dict(zip(iris.species.unique(), ['red', 'blue', 'green']))
scatter_matrix(iris, c=iris.species.map(lambda x: cmaps[x]), s=90, figsize=(12, 10));