0
$\begingroup$

In a recent post, we have seen (thanks to @kglr) how to create a custom pie chart

Clear["Global`*"];

coloring = 
Thread[{-1, -2, 0, 1, 2, 9} -> {Yellow, Purple, Green, Blue, Red, Cyan}];
data = {0, 0, -1, 1, 1, 2, 9, -2, 2, 1, 1, 1, 0, 0, 9, 9, -1, 0, 9, 2};

PieChart[ConstantArray[1, Length@data], 
SectorOrigin -> {{\[Pi]/2, "Clockwise"}, 1}, 
ChartStyle -> (data /. coloring), ChartBaseStyle -> EdgeForm[None]]

enter image description here

The above approach works very well when the dat file contains a list of integer numbers.

Now let's consider a two-dimensional data where the first row indicates the time, while the second row is the classification integer.

data2 = {{1, 0}, {2, 0}, {3, -1}, {4, 1}, {5, 1}, {6, 2}, {7, 9}, 
         {8, -2}, {9, 2}, {10, 1}, {11, 1}, {12, 1}, {13, 0}, 
         {14, 0}, {15, 9}, {16, 9}, {17, -1}, {18, 0}, {19, 9}, 
         {20, 2}};

I would like the following: wrap a curved axis around the pie chart indicating the time, let's say by printing the corresponding time every two steps (i.e., printing the values 0, 2, 4, 6, 8, ...) above the corresponding sectors of the pie chart. Any ideas?

$\endgroup$

1 Answer 1

3
$\begingroup$
coloring = Thread[{-1, -2, 0, 1, 2, 9} -> {Yellow, Purple, Green, Blue, Red, Cyan}];
time = data2[[All, 1]];
data = data2[[All, 2]];

labels = ConstantArray["", Length@time];
labels[[2 ;; ;; 2]] = time[[2 ;; ;; 2]];

PieChart[ConstantArray[1, Length@data], 
 SectorOrigin -> {{π/2, "Clockwise"}, 1}, 
 ChartStyle -> (data /. coloring), ChartBaseStyle -> EdgeForm[None], 
 ChartLabels -> Placed[labels, "RadialOutside"]]

enter image description here

Add the options PolarAxes -> {True, False}, PolarTicks -> {Automatic, None} and TicksStyle -> FontOpacity -> 0 to get

enter image description here

$\endgroup$
6
  • $\begingroup$ Nice! but my actual data contain about 2000 integers, so when I print the time labels is a real mesh. Is there a way to print only let's say 10 or 20 equally spaced labels? $\endgroup$
    – Vaggelis_Z
    Dec 13, 2019 at 16:52
  • $\begingroup$ That does not seem to work. If for example, I use Riffle[time[[2 ;; ;; 4]], "", {1, -1, 2}] then the time lables are misplaced. $\endgroup$
    – Vaggelis_Z
    Dec 13, 2019 at 17:00
  • $\begingroup$ @Vaggelis_Z, good catch. I will update with a fix in a moment. $\endgroup$
    – kglr
    Dec 13, 2019 at 17:05
  • $\begingroup$ @Vaggelis_Z, please see the new version. $\endgroup$
    – kglr
    Dec 13, 2019 at 17:10
  • $\begingroup$ Hmm, the question remains. What if I want to print only let's say 5 or 8 equally spaced time labels? $\endgroup$
    – Vaggelis_Z
    Dec 13, 2019 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.