Parrallel Coordinate Plot set tick label intepreter to LaTeX
조회 수: 3 (최근 30일)
이전 댓글 표시
Im looking to set the tick label intepreter of a parallelplot to by latex. I have found an existing solution but it does not seem to work in my MATLAB app:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606041/image.png)
However when I run the exact same code below it seems to work:
data = randi(1,10,3);
p = parallelplot(data);
S=struct(p);
S.Axes.TickLabelInterpreter='latex';
S.Axes.XTickLabel = {'$1^1$','$2\cdot2$','$\sqrt{3}$'};
댓글 수: 2
채택된 답변
Benjamin Kraus
2024년 2월 9일
편집: Benjamin Kraus
2024년 2월 13일
As the warning states, by calling struct on the object, you are accessing the internal implementation details of the chart, and the behavior of those internal implementation details are not guaranteed to work in any particular way. What you are doing is not a documented feature, and is unlikely to work reliably or consistently, and could break at any moment.
That being said, I suspect the issue is how you are setting the labels themselves.
Try this instead:
data = randi(1,10,3);
p = parallelplot(data);
p.CoordinateTickLabels = {'$1^1$','$2\cdot2$','$\sqrt{3}$'};
drawnow
s = struct(p);
s.Axes.TickLabelInterpreter='latex';
Some details on why this may work (but is not guaranteed):
- The parallelplot command creates a matlab.graphics.chart.ParallelCoordinatesPlot object.
- The ParallelCoordinatesPlot is completely in control of the internal axes that is used as an implementation detail of that chart. As such, it can (and will) update any Axes properties whenever it feels it is appropriate. This may cause it to stomp on any property values you've set on the Axes directly.
- When you set the TickLabelInterpreter property directly on the Axes, the ParallelCoordinatesPlot object has no way to know you did that. The same goes for the XTickLabel property. This means that (for example) if you save your figure and reopen the figure, any changes you've made to the Axes directly will be lost. It also means that none of this will work in the Live Editor (which leverages save/load internally).
- At some later point, the ParallelCoordinatesPlot object is going to redraw itself. At that point, it can (and will) update whatever properties on the Axes it feels is appropriate to create the desired picture, causing you to potentially lose any values you've customized on the internal Axes.
- This might mean that it changes the value of the TickLabelInterpreter property.
- It definitely means it will change the value of the XTickLabel property.
What I suspect is causing the difference in behavior you are experiencing:
- Because there is a property on the ParallelCoordinatesPlot object called CoordinateTickLabels, during the update of the ParallelCoordinatesPlot object, it is going to use the value of CoordinateTickLabels to replace the value of XTickLabel, stomping on any values you changed yourself.
- This update could occur for many reasons, but one reason that is likely to cause an update to run on the ParallelCoordinatesPlot is resizing your figure (or resizing the App). So, when you resize the figure or App, there is a good chance that any customization you've made to the internal Axes will be lost.
- Because there is a documented property on the ParallelCoordinatesPlot object called CoordinateTickLabels, you are much better off using that property (instead of Axis.XTickLabel) to change those labels. When you use CoordinateTickLabels, the ParallelCoordinatesPlot object will know about and correctly preserve the value across updates (and save/load).
- Because there is no documented property on the ParallelCoordinatesPlot object for changing the interpreter, there is no documented way to change the interpreter. If you chose to go the undocumented route and update the Axes directly, it may or may not work the way you expect, but it also makes it less likely that the ParallelCoordinatesPlot object will stomp on your change, so it is more likely to work.
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!