《科学计算科学计算 (27).pdf》由会员分享,可在线阅读,更多相关《科学计算科学计算 (27).pdf(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、4 4.6 6 GraphicsGraphics DecorationDecorationView point positioningColor processingClipping1 1View Point PositioningView Point PositioningAzimuth is a polar angle in the x-y plane,indicating rotation of the viewpoint.Positiveangels indicate counterclockwise,negative angelsindicate clockwise.Elevatio
2、n is an angle of gradient.Positive angelsindicate that the viewpoint is above the x-y plane,and negative angels indicate that the viewpoint isbelow the x-y plane.(1)Basic Syntaxview(az,el)Argument az is the azimuth,and el is the elevation.They are in degree.For 3-D plots,the default is azimuth=-37.5
3、and elevation=30.1 1View Point PositioningView Point Positioningx,y=meshgrid(0:0.1:2,1:0.1:3);z=(x-1).2+(y-2).2-1;subplot(2,2,1);mesh(x,y,z)title(Azimuth=-37.5circ,Elevation=30circ)subplot(2,2,2);mesh(x,y,z)view(0,90);title(Azimuth=0circ,Elevation=90circ)subplot(2,2,3);mesh(x,y,z)view(90,0);title(Az
4、imuth=90circ,Elevation=0circ)subplot(2,2,4);mesh(x,y,z)view(5,-60);title(Azimuth=-45circ,Elevation=-60circ)Example 1 Create a surface plot and display it with different viewpoints.=(1)2+(2)21(2)Other Syntax formatview(x,y,z)The values are the x-,y-,and z-coordinates of a vector that starts at thecen
5、ter of the plot box and points toward the camera.MATLAB calculates the azimuthand elevation angles using a unit vector pointing in the same direction.view(2)Uses the default line of sight for 2-D plots.view(3)Uses the default line of sight for 3-D plots.1 1View Point PositioningView Point Positionin
6、g(1)RGB tripletAn RGB triplet is a three-element row vector whose elements specify the intensities of the red,green,and blue components of the color.The intensities must be in the range 0,1;R G B red green blue0 0 1-blue1 0 0-red0 1 0-green1 1 1-white0 0 0-black2 2Color ProcessingColor Processing(2)
7、ColormapColormaps define the color scheme for many types of visualizations,such as surfaces and patches.The colormap is a three-column matrix of RGB triplets.parulajethsvhotcoolspringsummerautumnwintergraybonecopper cmap=colormap(parula(5)cmap=0.2081 0.1663 0.52920.0795 0.5159 0.83280.1986 0.7214 0.
8、63100.8266 0.7320 0.34640.9763 0.9831 0.0538Predefined Colormaps2 2Color ProcessingColor Processing Set the colormap for the current figure to one of the predefined colormaps.colormap cmapnamecolormap(cmap)surf(peaks)colormap hot2 2Color ProcessingColor Processing(2)Colormap Create the map matrixA t
9、hree-column matrix of RGB triplets specifies a custom colormap.You can create the matrix yourself,or you can call one of the predefined colormap functions to create the matrix.c=0,0.2,0.4,0.6,0.8,1.0;cmap=c,c,c;surf(peaks)colormap(cmap)Example 2 Create a gray map matrix.cmap=gray(6);2 2Color Process
10、ingColor Processing(2)Colormap(3)Set color shading propertiesThe shading function controls the color shading of surface and patch graphics objects.shading faceted shading flat shading interpFlat shading with superimposed black mesh lines.This is the default shading mode.Each mesh line segment and fa
11、ce has a constant color determined by the color value at the endpoint of the segment or the corner of the face that has the smallest index or indices.Varies the color in each line segment and face by interpolating the colormap index or true color value across the line or face.2 2Color ProcessingColo
12、r Processingx,y,z=cylinder(pi:-pi/5:0,10);colormap(lines);subplot(1,3,1);surf(x,y,z);shading flatsubplot(1,3,2);surf(x,y,z);shading interpsubplot(1,3,3);surf(x,y,z);Example 3 Display cone with different types of shading.The NaN in MATLAB is defined as the representation of not a number.We can make u
13、se of this feature to set the value to NaN corresponding to the part of a chart needs to be clipped.By doing so,the value equal to NaN will not be displayed when plotting.3 3ClippingClippingt=linspace(0,2*pi,100);x=sin(t);y=cos(t);p=y 0.5;y(p)=NaN;plot(x,y)axis(-1.1,1.1,-1.1,1.1)axis squaregrid onExample 4 Create three quarters of a circle.X,Y,Z=sphere(60);p=Z0.5;Z(p)=NaN;surf(X,Y,Z)axis(-1,1,-1,1,-1,1)axis equalview(-45,20)Example 5 Create three quarters of a sphere.
限制150内