Wolfram Mathematica 图中的 ListDensityPlot 缺少边缘点

问题描述 投票:0回答:1

我搜索了几个小时,但找不到解决此问题的方法。

使 Mathematica 中的函数 ListDensityPlot 像 MatrixPlot 函数一样显示绘图端点的命令是什么?

Plot using ListDensityPlot

Plot of the same data with MatrixPLot

两个数字都是用最小的工作示例制作的:

nx = 20;
ny = 20;

Table[
  u[[i]][[j]] = Exp[-(i - nx/2)^2 - (j - ny/2)^2]
  , {i, 2, nx - 1}, {j, 2, ny - 1}];

Table[u[[i]][[1]] = 1; u[[i]][[ny]] = 1;, {i, nx}];
Table[u[[1]][[j]] = 1; u[[nx]][[j]] = 1;, {j, ny}];

ListDensityPlot[u, InterpolationOrder -> 0]
MatrixPlot[u]

我希望绘图为每个网格点生成一个彩色方块,但显然 ListDensityPlot 缺少最后一个方块。

wolfram-mathematica mesh density-plot
1个回答
0
投票

ListDensityPlot
由于
InterpolationOrder -> 0
而被抵消。

例如。

GraphicsRow[{
  ListDensityPlot[{{1, 0, 0, 1, 0, 0, 1}, {1, 0, 0, 1, 0, 0, 1}},
   Mesh -> All, InterpolationOrder -> 0],
  ListDensityPlot[{{1, 0, 0, 1, 0, 0, 1}, {1, 0, 0, 1, 0, 0, 1}},
   Mesh -> All, InterpolationOrder -> 1]}]

没有

InterpolationOrder -> 0
就没有偏移问题。

nx = 20;
ny = 20;

u = Table[{i, j}, {i, 1, nx}, {j, 1, ny}];

Table[u[[i]][[j]] = Exp[-(i - nx/2)^2 - (j - ny/2)^2],
  {i, 2, nx - 1}, {j, 2, ny - 1}];

Table[u[[i]][[1]] = 1; u[[i]][[ny]] = 1;, {i, nx}];
Table[u[[1]][[j]] = 1; u[[nx]][[j]] = 1;, {j, ny}];

ListDensityPlot[u, InterpolationOrder -> 1]
MatrixPlot[u]
© www.soinside.com 2019 - 2024. All rights reserved.