You are on page 1of 3

import numpy as np #Array

import matplotlib.pyplot as plt #Graph


import sympy as sym #For math symbol like x, sin, tan

####################
#Must have in every code that have matplotlib!
%matplotlib inline
###################

#ARRAY (Numpy)
A = {1 , 3, 5, 7, 9}
B = {2, 4, 6, 8, 12}
#Set = useless piece of shit, can't use A[3], B[0] or anything at all

print(A)

a = list(sorted(A)) #Turn set into list (We sort because sometime set can show in random order)

x = np.array(a) #Turn list a to array

b = list(sorted(B))
y = np.array(b) #Turn list b to array

z = np.random.randint(low=0, high=12, size=(1,3)) #Random number creator (min = 0 , max = 11) and
MAKE AN ARRAY OF 1 row 3 columns
print(z)

domain = np.linspace(1, 3, 7) #Give ARRAYS of 7 values from 1 to 3 (will get something like [1, 1.3,
1.6, 2, 2.3, 2.6, 3])
domain = np.linspace(-2, 5, 20) #Give arrays of 20 values from -2 to 5
print(domain)

#GRAPH PLOTTING (matplotlib)


#plt.plot(x,y) #SIMPLEST GRAPH EVER (Use ARRAYS for both x,y)

#Naming x and y axis


plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.grid(color='red', ls='-.', lw = 2) #For grid, color = color, ls = line style '-', '--', '-.', ':', '', lw = line width

#Sometime we use subplot() for decoration/showing graph


sub = plt.subplot()
sub.set_xlim(0,25)
sub.set_ylim(-2, 15)
#The difference between each number is for Python to decide OR...

sub.set_xticks(np.linspace(0,25, 5)) #Set how much x will there be (5), start from what (0), end at what
(25)
sub.set_yticks(np.linspace(-2,15,8)) #8 Values on Y axis, start from -2 end at 15

#use sub.axvline(), sub.axhline() to highlight x = 0 , y = 0


sub.axvline(color='green', linewidth=5)
sub.axhline(color='green', linewidth=5)

######################################################
#Plotting multiple graphs
sub.plot(x,y, label='graph 1', lw=6, color='black')
sub.plot(y,x, label='graph 2')
sub.plot(y, y-x, marker="*", color='hotpink', label='graph 3', ms=9) #ms = marker size, pink * at each
point
sub.plot(y, y+x+1, color='green', marker='o', label='graph 4', ms=4) #green circle at each point
plt.show() #this lines is to make 100% sure the graph show

You might also like