matlabmatlab-figureinterpreter# MATLAB pie labels turn off interpreter

I want to plot a pie from a string vector that I get from another function.
These strings include `_`

symbols and the labels use the default interpreter and show special symbols instead of the original strings.
How can I turn off the interpreter there?
(I tried some commands such as `set(Groot, 'defaultLegendInterpreter', 'none')`

and `pie(categorical(str_vec),' Interpreter',' none')`

but nothing was good.)

```
str_vec = ["a_l" "a_l" "ab" "ab" "c_m"];
figure;pie(categorical(str_vec))
```

Solution

You can explore the `pie`

function with `edit pie`

, and with a little digging we can see that each pie "slice" is created as a `patch`

object, and each label is created as a `text`

object. Notably, the `text`

object creation only uses the following properties:

```
text(xtext,ytext,labels{i},...
'HorizontalAlignment',halign,'VerticalAlignment',valign,...
'Parent',cax,'Layer','front');
```

i.e. it doesn't set the `Interpreter`

property, which is `'tex'`

by default. This means we're not going to be able to set it while calling the `pie`

function and will have to do it after the chart creation.

You can set all of the text objects' interpreter to `'none'`

using

```
% Assign output objects to variable 'p', inc. the text labels
p = pie(categorical(str_vec));
% Get the text objects from the pie chart
labels = p( arrayfun( @(x) isa(x,'matlab.graphics.primitive.Text'), p ) );
% Set their interpreter
set( labels , 'Interpreter', 'none' );
```

If you're not familiar with `arrayfun`

which I'm using to condense things here, you can do the same thing with a loop

```
p = pie(categorical(str_vec));
for ii = 1:numel(p)
if isa(p(ii),'matlab.graphics.primitive.Text')
set( p(ii), 'Interpreter', 'none' );
end
end
```

Output:

- how to reshape a cell array to matrix in desired size
- Using Mat_CreateVer for MATLAB versions higher than 7.3
- Making a numpy ndarray matrix symmetric
- Matlab 2021 and2023 cross compatability
- How to plot figures at the end of the for loop MATLAB?
- Variable transfer from App Designer to general .m script file
- Anomalous behavior of the Simulink signal - Simscape
- What is the fastest method to searsch for a part of a matrix inside of a large matrix?
- Can I Prevent Git from Using XTerm Escape Sequences?
- Use VPA to evaluate tiny probabilities
- Generate Array of Random Numbers with Specified Standard Deviation and Mean
- Matlab update plot with multiple data lines/curves
- Matlab vectorize for loop (grid depends on loop index)
- How to use a flag variable to break all the for-loops in spmd statement?
- How to produce the indexes from pdist2 function in Octave?
- Calculation of sensitivity and specificity from confusion matrix
- How do I read comma separated values from a .txt file in MATLAB using textscan()?
- How do you code Garson's algorithm in matlab to find the relative importance of parameters when training a neural network model?
- add data label to a grouped bar chart in matlab
- Using 1D convolutional with same shape so it will work with FFT?
- super fast median of matrix in OpenCV (as fast as MATLAB)
- How to create a struct or type from a dictionary in Julia?
- MATLAB Delay an Input Signal
- Is there an Octave equivalent of Matlab's `contains` function?
- Matlab define callback function for mouse click on a biograph
- getting a return value from a function in MATLAB
- How to convert nifti file to AFNI file?
- load .mat file, but not on the workspace
- Fast plane fitting to many points
- Cubic spline interpolation vs polynomial interpolation