Wednesday, November 4, 2015

Menggunakan Matplotlib Bagian2


Grafik Scatter

from numpy import *
import matplotlib.pyplot as plt

x = linspace(0,2 * pi, 50)
 
plt.scatter(x, sin(x))
plt.show()
Legend


Output:

Membuat Legenda

from numpy import *
import matplotlib.pyplot as plt

x = linspace(0,2 * pi, 50)

#add label in plot command 
#plt.plot(x, sin(x), 'r-^', x, sin(2*x), 'b-o', label = 'sin')
#plt.plot(x,cos(x), label = 'cos')
#plt.legend()


plt.plot(x, sin(x), 'r-^', x, sin(2*x), 'b-o')
plt.plot(x,cos(x))

#as list in legend command
plt.legend(['sin', 'sin', 'cos'])

plt.show()


Output:

Title, label, and Grid

from numpy import *
import matplotlib.pyplot as plt

x = linspace(0,2 * pi, 50)

 
#plt.plot(x, sin(x), 'r-^', x, sin(2*x), 'b-o', label = 'sin')
#plt.plot(x,cos(x), label = 'cos')
#plt.legend()

plt.plot(x, sin(x), 'r-^', x, sin(2*x), 'b-o')
plt.plot(x,cos(x))

plt.xlabel = ('radians')
plt.ylabel('amplitudo', fontsize='large')
plt.title('Fungsi sin dan cos')

plt.legend(['sin', 'sin', 'cos'])

plt.grid()

plt.show()

Output:
Clearing and closing plots

Clearing and closing plots

from numpy import *
import matplotlib.pyplot as plt

x = linspace(0,2 * pi, 50)

 
#plt.plot(x, sin(x), 'r-^', x, sin(2*x), 'b-o', label = 'sin')
#plt.plot(x,cos(x), label = 'cos')
#plt.legend()

plt.plot(x, sin(x), 'r-^', x, sin(2*x), 'b-o')
plt.plot(x,cos(x))

plt.xlabel = ('radians')
plt.ylabel('amplitudo', fontsize='large')
plt.title('Fungsi sin dan cos')

plt.legend(['sin', 'sin', 'cos'])

plt.grid()

#cls will clear the current plot figure
plt.clf()

#close() will close the currently active plot window

#plt.close()

#plt.close('all')
plt.show()

Output:
Histogram

from numpy import *
import matplotlib.pyplot as plt

plt.hist(random.random_sample(1000), 30)

plt.show()

Output:
Sekian dan terimakasih. @wawanhn




Previous Post
Next Post

0 comments: