Matplot in python

What is Matplot?

Matplotlibrary

Matplot is a library for creating visualization with python.

How do plot lines bars and markers?

The grouped bar, stacked bar and horizontal bar chart examples and how to use bar_label

import matplotlib.pyplot as plt
import numpy as np
N=5
menMeans=(20353035-27)
womenMeans = (25323420-25)
menStd = (23412)
womenStd = (35233)
ind = np.arange(N) # the x locations for the groups
width = 0.35  # the width of the bars: can also be len(x) sequence
ind
array([0, 1, 2, 3, 4])
fig, ax = plt.subplots()
p1=ax.bar(ind, menMeans, width, yerr=menStd, label='Men')
p2=ax.bar(ind,womenMeans,width,
          bottom=womenStd,label='Women')
ax.axhline(0,color='gray',linewidth=0.8)
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind)
ax.set_xticklabels(('G1','G2','G3','G4','G5'))
ax.legend()

plt.show()
Horizontal bar chart
# Fixing random state for reproducibility
np.random.seed(19680801)
# Example data
people = ('Tom''Dick''Harry''Slim''Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))
fig, ax = plt.subplots()
hbars = ax.barh(y_pos, performance, xerr=error, align='center')
ax.set_yticks(y_pos)
ax.set_yticklabels(people)
ax.invert_yaxis()  # labels read top-to-bottom
ax.set_xlabel('Performance')
ax.set_title('How fast do you want to go today?')
# Label with specially formatted floats
ax.bar_label(hbars, fmt='%.2f')
ax.set_xlim(right=15)  # adjust xlim to fit labels

plt.show()
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
 import numpy as np
 import sympy
x=np.linspace(-5,2,100)
y1=x**3+5*x**2+10
y2 = 3*x**2 + 10*x
y3 = 6*x + 10
fig,ax=plt.subplots()
ax.plot(x,y1,color="blue",label="y(x)")
ax.plot(x,y2,color="red",label="y'(x)")
ax.plot(x, y3, color="green", label="y”(x)")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.legend()


import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format='svg'
fig=plt.figure(figsize=(8,2.5),facecolor="#f1f1f1")
 left, bottom, width, height = 0.10.10.80.8
ax=fig.add_axes((left,bottom,width,height),facecolor="#e1e1e1")
x=np.linspace(-2,2,1000)
y1=np.cos(40*x)
y2 = np.exp(-x**2)
ax.plot(x, y1 * y2)
ax.plot(x, y2, 'g')
ax.plot(x, -y2, 'g')
ax.set_xlabel("x")
ax.set_ylabel("y")
fig.savefig("graph.png", dpi=100, facecolor="#f1f1f1")
fig, axes = plt.subplots(nrows=3, ncols=2)
x = np.linspace(-555)
y = np.ones_like(x)
def axes_settings(fig,ax,title,ymax):
   ax.set_xticks([])
   ax.set_yticks([])
   ax.set_ylim(0, ymax+1)
   ax.set_title(title)
fig, axes = plt.subplots(14, figsize=(16,3))




Post a Comment

0 Comments