Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Plots 20.11.

22, 21:49

Plots
You will need 2 libraries: matplotlib.pyplot and numpy.

In [1]: import matplotlib.pyplot as plt


import numpy as np

Then you should get your data and store it in variables in a list.

In [2]: xWerte = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
yWerte = [6.58, 6.08, 7, 6.42, 6.18, 6.3, 5.4, 6.5, 6.41, 6.57, 5.86, 6.27

These are the basic commands to create a graph:

In [4]: fig = plt.figure() #defines fig


ax1 = fig.add_subplot(1,1,1) #adding a plot (amount of graphs, what column, amo
ax1.plot (xWerte, yWerte, '.b') #plotting using the x and y axis data and what
ax1.plot (xWerte, yWerte, '-r') #you can plot multiple stuff

[<matplotlib.lines.Line2D at 0x7fa156257400>]
Out[4]:

http://localhost:8888/nbconvert/html/Documents/Actual%20School%20shiz/Informatik/Untitled%20Folder/Plots.ipynb?download=false Page 1 of 3
Plots 20.11.22, 21:49

In [5]: #ax1.grid() --> optional


#plt.suptitle("sus per imposter") ---> adds a title
#plt.xlabel ("yuhh") ---> adds a label for x axis
#plt.ylabel ("yuhhhhhhhhh") ---> adds a label for y axis

Another example would be a plot using a function:

In [6]: import numpy as np


import matplotlib.pyplot as plt

def yessir(x):
y = x**4532342 #the stars define "to the power of...."
return y

x = np.array ([1,2,3,4,5,6,7,8,9])
y = yessir(x)

plt.suptitle("sus per imposter")


plt.xlabel ("yuhh")
plt.ylabel ("yuhhhhhhhhh")

plt.grid()
plt.plot(x,y)

[<matplotlib.lines.Line2D at 0x7fa15654dcd0>]
Out[6]:

http://localhost:8888/nbconvert/html/Documents/Actual%20School%20shiz/Informatik/Untitled%20Folder/Plots.ipynb?download=false Page 2 of 3
Plots 20.11.22, 21:49

The same principles are used here as well. But here there aren't that many
commands used.

http://localhost:8888/nbconvert/html/Documents/Actual%20School%20shiz/Informatik/Untitled%20Folder/Plots.ipynb?download=false Page 3 of 3

You might also like