World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Rajesh Naik
a year ago
python -m pip install -U pip
python -m pip install -U matplotlib
conda install matplotlib
from matplotlib import pyplot as plt
#matplotlib.pyplot.subplots
matplotlib.pyplot.subplots(nrows=1,ncols=1,*,sharex=False,sharey=False,squeeze=True,
subplot_kw=None,gridspec_kw=None,**fig_kw)
import matplotlib.pyplot as plt
import numpy as np
x = np.array([0, 1, 2, 3])
y1 = np.array([2, 4, 6, 8])
y2 = np.array([3, 6, 9, 12])
y3 = np.array([40, 30, 20, 10])
y4 = np.array([75, 15, 55, 5])
# Create subplots
fig, ax = plt.subplots(2, 2, sharex='col', sharey='row')
ax[0][0].plot(x,y1,'b')
ax[0][1].plot(x,y2,'g')
ax[1][0].plot(x,y3,'y')
ax[1][1].plot(x,y4,'r')
import matplotlib.pyplot as plt
import numpy as np
x = np.array([2, 6])
y = np.array([0, 25])
plt.title("line plot")
plt.plot(x, y)
plt.show()
#matplotlib.pyplot.hist
matplotlib.pyplot.hist(x, bins=None, range=None, density=False, weights=None, cumulative=False,
bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False,
color=None, label=None, stacked=False, *, data=None, **kwargs)
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(70, 10, 200)
plt.hist(x, 15, density=True, facecolor='g', alpha=0.75)
#plt.hist(x)
plt.show()
#matplotlib.pyplot.bar
matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["Samsung", "Apple", "Nokia", "Xiomi"])
y = np.array([70, 50, 30, 90])
plt.bar(x,y)
plt.show()
#matplotlib.pyplot.scatter
matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None,
vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None,
plotnonfinite=False, data=None, **kwargs)
import matplotlib.pyplot as plt
import numpy as np
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()
#matplotlib.axes.Axes.pie
Axes.pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6,
shadow=False, labeldistance=1.1, startangle=0, radius=1, counterclock=True,
wedgeprops=None, textprops=None, center=(0, 0), frame=False, rotatelabels=False,
*, normalize=True, data=None)
import matplotlib.pyplot as plt
labels = 'Oxygen', 'Nitrogen', 'Other'
sizes = [21, 78, 1]
explode = (0, 0.1, 0) # only "explode" the 2nd slice (i.e. 'Oxygen')
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()
#matplotlib.pyplot.boxplot
matplotlib.pyplot.boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None,
widths=None, patch_artist=None, bootstrap=None, usermedians=None, conf_intervals=None,
meanline=None, showmeans=None, showcaps=None, showbox=None, showfliers=None, boxprops=None,
labels=None, flierprops=None, medianprops=None, meanprops=None, capprops=None,
whiskerprops=None, manage_ticks=True, autorange=False, zorder=None, *, data=None)
import matplotlib.pyplot as plt
import numpy as np
# Creating dataset
np.random.seed(10)
data = np.random.normal(100, 20, 400)
fig = plt.figure(figsize =(10, 7))
# Creating plot
plt.boxplot(data)
# show plot
plt.show()