1 / 15

PYTHON

Learn how to create 2D and 3D graphs using Python with different styles and markers for effective visualization. Includes line graphs, markers, multiple subplots, and 3D wireframe and surface plots.

backman
Télécharger la présentation

PYTHON

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PYTHON Graphs Prof. Muhammad Saeed

  2. Graph 2D (Simple Line Graphs) Python Dept. Of Comp. Sc. & IT, FUUAST

  3. Graph 2D • import matplotlib.pyplot as plt • from numpy import arange, sin, exp, pi • LineGraph(Colors ): • x= arange(-12*pi, 12*pi, 0.1) • y=exp(-0.05*x)*sin(x) • plt.plot(x, y, ‘ob’) • plt.plot(x, y, ‘-r’) • plt.plot(x, y, ‘-sm’) • plt.plot(x,y, color=‘#ff0000’) • plt.show() Python Dept. Of Comp. Sc. & IT, FUUAST

  4. Graph 2D Color, Marker & Line Style Python Dept. Of Comp. Sc. & IT, FUUAST

  5. Graph 2D • import matplotlib.pyplot as plt • from numpy import arange, sin, exp, pi • LineGraph(Title and Labels ): • x= arange(-12*pi, 12*pi, 0.1) • y=exp(-0.05*x)*sin(x) • plt.plot(x, y, ‘b’) • plt.title(‘Graph Damped Oscillator’) • plt.xlabel(‘Angle’) • plt.ylabel(‘Oscillations’) • plt.show() Python Dept. Of Comp. Sc. & IT, FUUAST

  6. Graph 2D • Graph With Marker and Line Styles: • x= arange(-12*pi, 12*pi, 0.1) • y=exp(-0.05*x)*sin(x) • plt.plot(x, y, alpha = 0.5, color = ‘#FF7F00’, • label = ’Line Label’, linestyle= ‘-.’, linewidth = 3, • marker = ‘o’, markeredgecolor = ‘#000000’, • markeredgewidth= 2, markerfacecolor = ‘#FF7F00’, • markersize=10) • plt.show() Python Dept. Of Comp. Sc. & IT, FUUAST

  7. Graph 2D • import matplotlib.pyplot as plt • from numpy import arange, sin, cos, pi • MultipleGraphs in One Figure: • x= arange(-12*pi, 12*pi, 0.1) • y1=sin(x) • y2=cos(x) • y3=sin(x)/x • plt.plot(x, y1, x, y2, x, y3) • plt.legend(‘Sine’,’Cosine’,’Sine/Angle’).draggable(True) • plt.show() Python Dept. Of Comp. Sc. & IT, FUUAST

  8. Graph 2D • import matplotlib.pyplot as plt • from numpy import arange, sin, cos, pi • MultipleGraphs in One Figure: • x= arange(-12*pi, 12*pi, 0.1) • y1=sin(x) • y2=cos(x) • y3=sin(x)/x • plt.plot(x, y1) • plt.plot(x,y2) • plt.plot(x,y3) • plt.legend(‘Sine’,’Cosine’,’Sine/Angle’).draggable(True) • plt.show() Python Dept. Of Comp. Sc. & IT, FUUAST

  9. Graph 2D Multiple Subplots in a Window: • import matplotlib.pyplot as plt • Import numpy as np • fig, ax=plt.subplots(2,2, sharex='all' ) #, sharey=‘all’) • x= np.linspace(-12*pi, 12*pi, 600) • y1=np.sin(x) ; • y2=np.tan(x); • y3=np.sin(x)/x • y4=np.exp(-0.05*x)*np.sin(x) • ax=np.ravel(ax) • ax[0].plot(x,y1,'r') • ax[1].plot(x,y2,'g') • ax[2].plot(x,y3,'b') • ax[3].plot(x,y4,'m') Python Dept. Of Comp. Sc. & IT, FUUAST

  10. Graph 3D (Wireframe and surface) Python Dept. Of Comp. Sc. & IT, FUUAST

  11. Graph 3D Curves: • import matplotlib.pyplot as plt • Import numpy as np • from mpl_toolkits.mplot3d import Axes3D • x = linspace(-8*pi,8*pi,400) • y = x*sin(x) • x = 2*cos(x) • z = x*y • fig = plt.figure() • ax=fig.gca(projection='3d') • ax.plot(x,y,z) • plt.show() Python Dept. Of Comp. Sc. & IT, FUUAST

  12. Graph 3D Wireframe: • import matplotlib.pyplot as plt • Import numpy as np • from mpl_toolkits.mplot3d import Axes3D • fig = plt.figure() • ax = fig.add_subplot(111, projection='3d') • x=np.linspace(-7,7,200) • y=np.linspace(-7,7,200) • xx,yy=np.meshgrid(x,y) • zz=np.sin(np.sqrt(xx**2+yy**2))/np.sqrt(xx**2+yy**2) • ax.plot_wireframe(xx, yy, zz, rstride=5, cstride=5) Python Dept. Of Comp. Sc. & IT, FUUAST

  13. Graph 3D Surface: • import matplotlib.pyplot as plt • Import numpy as np • from mpl_toolkits.mplot3d import Axes3D • fig = plt.figure() • ax = fig.add_subplot(111, projection='3d') • x=np.linspace(-7,7,200) • y=np.linspace(-7,7,200) • xx,yy=np.meshgrid(x,y) • zz=np.sin(np.sqrt(xx**2+yy**2))/np.sqrt(xx**2+yy**2) • ax.plot_surface(xx, yy, zz, rstride=5, cstride=5) Python Dept. Of Comp. Sc. & IT, FUUAST

  14. Graph 3D Surface: • import matplotlib.pyplot as plt • Import numpy as np • from mpl_toolkits.mplot3d import Axes3D • fig = plt.figure() • ax = fig.add_subplot(111, projection='3d') • u = np.linspace(0, 2 * np.pi, 100) • v = np.linspace(0, np.pi, 100) • x = 10 * np.outer(np.cos(u), np.sin(v)) • y = 10 * np.outer(np.sin(u), np.sin(v)) • z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) • ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b',cmap='jet') • ax.axis('square') • plt.show() Python Dept. Of Comp. Sc. & IT, FUUAST

  15. END Python Dept. Of Comp. Sc. & IT, FUUAST

More Related