#!/usr/bin/env python
# coding: utf-8

# # Einführung in Pyplot
# ## Pyplot

# In[1]:


import numpy as np
import matplotlib.pyplot as plt
#%matplotlib notebook
get_ipython().run_line_magic('matplotlib', 'inline')
#%matplotlib qt5agg


# Für pyplot gibt es einen _expliziten_ Modus, bei dem in ein vorgegebenes Koordinatensystem gezeichnet wird 

# In[2]:


x = np.linspace(0, 5*np.pi)
y = np.cos(x)
fig = plt.figure()
fig.show()


# In[3]:


ax = fig.add_axes((.1,.1,.8,.8))
ax.plot(x, y); # Polygozug zu den Punkten (x[i], y[i]) i = 0 ...


# In[4]:


fig, ax = plt.subplots() # kompakter
ax.plot(x,-y)


# Im _impliziten_ Modus sucht sich pyplot das Koordinatensystem in das gezeichnet wird.

# In[5]:


plt.figure() # erzeugt ein neues Bild
plt.plot(x, y) # zeichne in das Koordinatensystem des letzten Bildes 


# Farben als Kürzel
# 
# |b   |g    |r  |c   |m      |y     |k    |w    |
# |----|-----|---|----|-------|------|-----|-----|
# |blue|green|red|cyan|magenta|yellow|black|white|

# In[6]:


linestyles = ['-', '--', '-.', ':']


# In[7]:


fig, ax = plt.subplots()
for count, ls in enumerate(linestyles):
    ax.plot([count, count], [0, 1], ls, linewidth=3)


# In[8]:


fig, ax = plt.subplots()
markers = ['.', ',', 'o', '^', 'v', '<', '>', '1', '2', '3', '4', 's', 'p',]
markers += ['*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_']
y = np.linspace(0, 1, 4)
x = np.zeros_like(y)
for i, m in enumerate(markers):
    ax.plot(x+i, y, m, markersize=11)


# In[9]:


fig, ax = plt.subplots()
x = np.linspace(0, 5*np.pi, 201)
y = np.cos(x)
ax.plot(x, y, 'c', linewidth=2);


# Mehrere Graphen in einem Bild

# In[10]:


fig, ax = plt.subplots()
z = np.sin(x**2)
ax.plot(x, y)
ax.plot(x, z); 


# Hier gibt es noch nicht genug Punkte

# In[11]:


x = np.linspace(0, 5*np.pi, 1101)
y = np.cos(x)
z = np.sin(x**2)
ax.clear()
ax.plot(x, y)
ax.plot(x, z);


# Format ändern, Titel und Legende

# In[12]:


fig, ax = plt.subplots(figsize=(10, 2), facecolor='lightskyblue')
fig.suptitle("Graph")
x = np.linspace(-5, 5, 200)
ax.plot(x, np.sinc(x), label='$\\sin(x)/x$')
ax.set_title('sinc',loc='right')
ax.legend(loc="upper right");


# In[13]:


ax.plot(x, np.sin(3*np.pi*x), 'w')
ax.set_title("Sinus",loc='left')
ax.set_facecolor('k')


# In[14]:


fig, axs = plt.subplots(2, 1)   # 2 x 1 Koordinatensysteme 
axs[0].plot(x, np.sin(3*np.pi*x), 'w')
axs[1].plot(x, np.cos(2*np.pi*x), 'w')
axs[0].set_title('Sinus')
axs[1].set_title('Cosinus')
for ax in axs:
    ax.set_facecolor('k')


# In[15]:


def n_eck(n):
    ''' Eckpunkte eines n-Ecks'''
    x = [np.sin(2*np.pi*j/n) for j in range(n+1)]
    y = [np.cos(2*np.pi*j/n) for j in range(n+1)]
    return x, y


# In[16]:


fig, ax = plt.subplots()
for n in range(3, 9):
    ax.plot(*n_eck(n))  # <- Auspacken
ax.axis('equal');


# In[ ]:




