Mathematica数据处理(5)--Plot

来源:互联网 发布:wireshark过滤端口 编辑:程序博客网 时间:2024/05/18 02:39
今天这一篇文章,我们来讲一下画图

我们会分为2D和3D的来分别讲述

首先让我们看一下在Mathematica中画图的函数有多少
fun = Names["*Plot"];Grid[Partition[fun, 3, 1],Background -> {None, {{LightBlue, LightRed}}}, Frame -> All]
来看看,这是结果
很明显,我这里要讲完这么多是不可能的,所以我们就挑几个讲一下

首先讲2D的
最重要的当然是Plot,相信大家都已经会用了,我就放一个简单的例子

Plot[2*E^(2*x), {x, 0, 4}, PlotLabel -> Style[Plot, 24],ImageSize -> Large]
得到下面的图
下面讲一下 对数图,对数线性图,双对数图
我们以对数图为例讲一下
对数图其实就是将y轴的坐标做了Log的运算。
例如上图,在对数图下面就是一条直线,这么做是为了更好发现数据之间的关系的
下面举个例子
GraphicsRow[{  LogPlot[2*E^(2*x), {x, 0, 4}, PlotLabel -> Style[LogPlot, 24],    ImageSize -> Medium],  (*以y为对数坐标画图,相当于y轴坐标做了一个Log的变换,注意此时y轴为对数刻度,只是坐标变了,数字并没有变化*)  LogLinearPlot[2*E^(2*x), {x, 1, 4},    PlotLabel -> Style[LogLinearPlot, 24], ImageSize -> Medium],  (*x是对数*)  LogLogPlot[2*E^(2*x), {x, 1, 4}, PlotLabel -> Style[LogLogPlot, 24],    ImageSize -> Medium]   (*x,y都是对数*)  }]
得到如下的图

当然,还有极坐标画图
PolarPlot[t, {t, 0, 20}]
得到如下的图


下面讲一下3D的作图
Plot3D是可以直接画出3D的图像的
f[x_, y_] := Sin[x^2 + y^2]/(x^2 + y^2 + 1);Plot3D[f[x, y], {x, -4, 4}, {y, -4, 4},PlotLabel -> Style[Plot3D, 24], PlotTheme -> "Classic"]
如下图

有的时候,对于三维的图,虽说很直观,但是一些数据并不容易观察出,此时我们就需要借助
密度图 和 绘制等高线

GraphicsRow[{  DensityPlot[f[x, y], {x, -4, 4}, {y, -4, 4},    PlotLabel -> Style[DensityPlot, 24], ImageSize -> Medium,    ColorFunction -> "CMYKColors"],  ContourPlot[f[x, y], {x, -4, 4}, {y, -4, 4},    PlotLabel -> Style[ContourPlot, 24], ImageSize -> Medium,    ColorFunction -> "CMYKColors"]  }](*一般来说,颜色越浅,对应的函数值就越大*)(*等高线图就是把密度图分成若干份*)
得到如下的图

我们还可以把图画的更好一些,加一些注释
Column[{  DensityPlot[f[x, y], {x, -4, 4}, {y, -4, 4},    PlotLabel -> Style[DensityPlot, 24], ImageSize -> Medium,    ColorFunction -> "CMYKColors"],  BarLegend[{"CMYKColors", range}, LegendLayout -> "Row",    LegendMarkerSize -> 400]  }, Center]
得到下面的图
可以看到黑色的地方函数值是最大的,和我们在3D图上看到的是一样的

最后我们看三种 球 的画法
GraphicsRow[{  ParametricPlot3D[{Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]}, {v, 0,     2 Pi}, {u, 0, 2 Pi}, PlotLabel -> Style["三位参数图", 24],    ImageSize -> Medium, ColorFunction -> ColorData["TemperatureMap"]],  SphericalPlot3D[1, {\[Theta], 0, 2 Pi}, {\[Phi], 0, 2 Pi},    PlotLabel -> Style["三维球面图", 24], ImageSize -> Medium,    ColorFunction -> ColorData["TemperatureMap"]],  RevolutionPlot3D[{Cos[t], Sin[t]}, {t, -Pi/2, Pi/2},    PlotLabel -> Style["三维旋转图", 24], ImageSize -> Large,    ColorFunction -> ColorData["TemperatureMap"]]  }, ImageSize -> Full]
得到下面的图



上面就是关于Mathematica画图的一些知识


2016/8/11

以上,所有



0 0