How can i change the colours of segmentation on a chart pie?
Show older comments
Hey,
I have plotted a pie chart, but the colours of the segmentation does not appeal to me...is there any way I can alter the colours?
Thank you.
Accepted Answer
More Answers (1)
Starting in R2023b we have a new piechart which is a little easier to change colors for. Here are some demos with our built in color palettes, and then one with a custom palette. You can use the colororder function to change them or set the ColorOrder property on the PieChart object.
vals = [1 1 2 3 5];
figure
piechart(vals)
colororder("sail")
figure
piechart(vals)
colororder("reef")
figure
piechart(vals)
colororder("meadow")
figure
piechart(vals)
colororder("earth")
figure
% use validatecolor as an easy way to turn hex values into RGBs
mypalette = validatecolor(["#3BA8ED" "#ED4747" "#2FEDD1" "#ED9418" "#24ED5D"], "multiple");
piechart(vals)
colororder(mypalette)
2 Comments
Hi Dave,
thank you for this solution which in principal worked perfectly for me.
Unfortunately I now have the problem that the colors appear "dimmed down" and only if I hover over one segment it is displayed in the color specified in my code. If I save my piechart as png or any other format I have tried it will not show the correct color but the dimmed version,
Do you know of any solution?
Thank you in advance!
Actually I do! The piechart uses transparency by default, which allows it to show the sort-of highlight effect, but that makes the colors look a little muted.
You can control the amount of transparency with the FaceAlpha property, and if you set it to 1 it will produce full opacity and the colors won't look muted. Here's the same palette as above,
vals = [1 1 2 3 5];
mypalette = validatecolor(["#3BA8ED" "#ED4747" "#2FEDD1" "#ED9418" "#24ED5D"], "multiple");
figure
piechart(vals, 'FaceAlpha', 1)
colororder(mypalette)
Categories
Find more on Pie Charts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




