# ArrayPlot in polar coordinates?

I have a 2-D array ($$360 \times 512$$). The 360 rows represents the azimuthal angle from (0° to 359°) and the 512 columns are radial segments.

This is the ArrayPlot of my data.

ArrayPlot[data, Frame -> True, FrameLabel -> {{Style["Range", 18], None},
{Style["Azimuth", 18], None}}, ColorFunction -> "Rainbow",
ImageSize -> 480, AspectRatio -> 1, PlotRangePadding -> None]


I would like to know how to plot the data in polar coordinates. I see there were already some discussions on this topic, e.g. How to make a ArrayPlot/MatrixPlot in polar coordinates?

I tried to follow the steps, but did not succeed. Not sure if my array is too large, the running time is extremely long. For example,

polararrayplot[array_, colourfunc_] :=
SectorChart[Map[Style[{1, 1}, colourfunc[#]] &, array, {2}], SectorSpacing -> None];

polararrayplot[data, ColorData["Rainbow", #] &]


May I know which way of plotting suggested in the above link is more efficient? Or there is any newly available function in Mathematica in recent years? I am using Version 11.1.

I have uploaded the data here or here if anyone would like to take a look.

Many thanks in advance.

• Please share the code showing what you tried! – mjw Mar 29 at 3:17
• @mjw Code uploaded – wkong Mar 29 at 3:52
• I decreased the array size (download to 36 x 10) and it finally plotted the polar graph successfully. I also disabled ColorFunctionScaling and it seems run faster. What other function can be disabled in SectorChart in order to speed up the plotting? In the output of SectorChart, the sector can be highlighted individually by clicking the sector. Can this be disabled? Thanks. – wkong Mar 29 at 7:04
• I mean in the output of SectorChart, we can interact with the sectors. Just wonder if the machine time can be decreased by disabling such functions. – wkong Mar 29 at 7:27

## 2 Answers

Here is an alternative approach, which is a slightly simplified version of the "diskfun" methods available in Chebfun. One might wish to note the similarities and differences between this method and the method in this previous answer.

Briefly: I will construct an interpolaing function to the OP's data by using SVD to decompose the data into a "radial part" and "angular part".

Import the data first:

wkong = Import["https://pastebin.com/raw/rnig0VMq", "CSV"];


Then, prepare the data for the disk interpolant construction by padding and reflecting it appropriately:

rflct = Append[#, First[#]] &[Join[Reverse[Drop[wkong, None, 1], 2], wkong, 2]];


Now, perform the SVD:

{u, s, v} = SingularValueDecomposition[rflct, Min[Dimensions[rflct]]];


Construct the components of the interpolating function:

u[[{1, -1}]] = Mean[u[[{1, -1}]]];
uf = ListInterpolation[#, {{0, 2 π}}, PeriodicInterpolation -> True] &
/@ Transpose[u];
vf = ListInterpolation[#, {{-1, 1}}] & /@ Transpose[v];
s = Diagonal[s];


Let us look at a log plot of the singular values:

ListLogPlot[s]


It looks like we should be fine with taking the first $$100$$ components for plotting; thus,

With[{p = 100},
DensityPlot[Total[Through[Take[vf, p][Norm[{x, y}]]] Take[s, p]
Through[Take[uf, p][ArcTan[x, y]]],
Method -> "CompensatedSummation"], {x, y} ∈ Disk[],
ColorFunction -> "ThermometerColors", PlotPoints -> 95]]


It takes a bit of time to plot, but not too overly long. You can always increase or decrease p as needed.

• Many thanks J.M.! The method works very well. If I want to plot more details, I should increase p or PlotPoints? Besides, may I know what does p actually refer to? – wkong Apr 1 at 3:20
• You can try increasing both for more detail, but of course at the expense of increased computation time. As noted, I just took the first p singular values and vectors to generate an approximation to your data. – J. M. is away Apr 1 at 4:11

For your type of data, you may want to consider a more continuous type of plot than the sector chart that the solution you reference uses. I would suggest DensityPlot. Here's an example:

data = Import["~/Downloads/data.csv"];
interp = Interpolation@Flatten[MapIndexed[{#2, #} &, data, {2}], 1];

DensityPlot[
interp[(Arg[x + y I] + Pi)/Degree, Sqrt[x^2 + y^2]],
{x, -500, 500},
{y, -500, 500},
RegionFunction -> Function[{xx, yy}, 0 < Sqrt[xx^2 + yy^2] < 500],
PlotPoints -> 100,
Exclusions -> None,
Frame -> False
]


I got the idea of using Arg instead of other alternatives from this answer.