Saturday, March 28, 2020

how to set xticks and yticks in matplotlib in datascience using python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np

axes = plt.axes()
axes.set_xlim([-5,5])
axes.set_ylim([0,1.0])
axes.set_xticks([-5,-4,-3,-2,-1,0,1,2,3,4,5])
axes.set_yticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
plt.plot(x, norm.pdf(x))
plt.plot(x,norm.pdf(x, 1.0, 0.5))
plt.show()


output:

matplot lib basics for datascience using python

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np


x=np.arange(-3,3,0.001)
plt.plot(x,norm.pdf(x))
plt.show()

output:


Multiple plots in one diagram:

plt.plot(x,norm.pdf(x))
plt.plot(x,norm.pdf(x,1.0,0.5))
plt.show()


save the plot in file


output:


how to  save the plots in folders:

plt.plot(x,norm.pdf(x))

plt.plot(x,norm.pdf(x,1.0,0.5))

plt.savefig('C:\\Users\\Onyx1\\Pictures\\matplotlib\\matplot_two_plot.jpg', format='jpg')


percentiles and moments in datascience using python

import numpy as np
import matplotlib.pyplot as plt

vals=np.random.normal(0,0.5,10000)

plt.hist(vals,50)
plt.show()

output:


np.percentile(vals,50)
-0.0006091649949392949
np.percentile(vals,90)
0.6333622008770741

Movements:
import numpy as np
import matplotlib.pyplot as plt

vals=np.random.normal(0,0.5,10000)

plt.hist(vals,50)
plt.show()

output:
np.mean(vals)
0.002411873839262703

np.var(vals)
0.25225058001660977

import scipy.stats as sp
sp.skew(vals)
0.016161251790655015

sp.kurtosis(vals)
-0.034877789070170806


python class topic video