Mathematica数据处理(7)--散点图(下)

    xiaoxiao2025-02-03  21

    今天我们来讲一下怎么画三维的散点图

    先讲三个最基本函数

    ListPlot3D

    ListDensityPlot

    ListContourPlot

    和前面讲的一样,直接看三维的图比较直观,但是能理解的信息比较少,只能呈现一面的信息。

    直接看下面的例子

    data = Table[Sum[Sin[RandomReal[10, 2].{x, y}], {10 i}], {i, 3}, {x, 0, 5, .3}, {y, 0, 5, .3}];

    产生一组数据

    range = #[data[[1]]] & /@ {Min, Max} Row[{ ListPlot3D[data[[1]], ColorFunction -> "TemperatureMap", ImageSize -> 300, PlotLabel -> Style[ListPlot3D, 24]], ListDensityPlot[data[[1]], ColorFunction -> "TemperatureMap", ImageSize -> 300, PlotLabel -> Style[ListDensityPlot, 24]], ListContourPlot[data[[1]], ColorFunction -> "TemperatureMap", ImageSize -> 300, PlotLabel -> Style[ListContourPlot, 24]] }]

    画图,找到其中最大值和最小值,后面的图例有用

    得到下图

    把图修饰的好看一点,加一下图例

    pic1 = ListContourPlot[data[[1]], ColorFunction -> "TemperatureMap", ImageSize -> 300, PlotLabel -> Style[ListContourPlot, 24]]; pic2 = BarLegend[{"TemperatureMap", range}, LegendLayout -> "Row", LegendMarkerSize -> 300]; Column[{pic1, pic2}, Center]

    得到下面的图

    ****************************************

    这里我想讲一下ListPlot3D里面输入n×n时候的意思

    知道的话可以直接跳过,其实就是其帮助文档的第一条

    n×n的相当于定义了曲面的高度

    a = {{0, 0, 0, 0}, {0, 10, 10, 0}, {0, 10, 10, 0}, {0, 0, 0, 0}}; ListPlot3D[a, ImageSize -> Large, ColorFunction -> "TemperatureMap"]

    这两行就相当于是其实相当于 在( 0 , 0 )的位置高度为0,即坐标( 0 , 0 , 0 ),在( 2 , 3 )的位置高度为10,即坐标( 2 , 3 , 10 )

    画出来的图像是这样的

    *****************************

    下面继续

    讲一下 点集对数图 点集双对数图

    有的时候我们直接看数据发现不了规律,又是不妨转换一下坐标,就能发现其中的奥秘

    我们来看一个下面的例子

    动物的体重与大脑重量的关系

    data = ExampleData[{"Statistics", "AnimalWeights"}]

    获取数据

    Grid[data, Frame -> All,Background -> {None, {{LightBlue, LightGreen}}}]

    得到如下的数据

    光看数据也看不出什么规律,我们把他在图上画一下,看一下呈现什么样子

    {animal, brian, weight} = Transpose[data]; chardata = Transpose@{brian, weight}; ListPlot[chardata]

    并不能看出什么规律,这时我们考虑转换坐标,转换成对数坐标

    Row[{ ListLogPlot[chardata, ImageSize -> Medium], ListLogLogPlot[ Table[Tooltip[chardata[[i]], animal[[i]]], {i, 1, 28}], ImageSize -> Medium, Frame -> True, FrameLabel -> {"大脑平均重量", "平均体重(公斤)"}]

    得到如下的图

    可以看到在双对数图上,数据呈现 线性关系

    2016/8/13

    以上,所有

    转载请注明原文地址: https://ju.6miu.com/read-1296047.html
    最新回复(0)