Creating a custom axis
50 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am looking to create a custom x axis for a 3D surface plot. My x data has a form similar to V = [0 5 10 15 20 15 10 5 0 -5 -10 -15 -20 -15 -10 -5 0]. Each point will have a corrosponding y and z point. When I plot them how ever the similar x points overlap since they have the same value. I would like to make the x axis use the values in the matrix without overlap but instead writing them in the order they appear in the matrix. If possible I'd like to preserve the numerical value without converting to text.
Currently I create a variable for the x axis V similar to above. In the surafce plat I Use V instead of T as I show below. But this causes one have of the data to be graphed over the other half. I then created a linear matrix of datat points from 1 to 161 and used that at the x axis. This works and I get the graph I am looking for however the x axis label is wrong. I would like to force the axis to use V. To do this I tried to convert to a string and label the x axis with it. QualityFactor is a matrix of size 200x161 and FreqS is of size 200x1. When I graph this I get the following
The graph axis forces itself to 200 points along the x axis. To correct this I force the axis to 161 to match the size of the data and I get the following
In the first case I get the axis I want but the data is compressed and doesn't fill the axis. When I force the axis I get the size plot I want but the axis is cut off and doesn't rescale to match the data.
How might I fix this issue?
Thank you
VoltMax = 200;
VoltStep = 5;
VSD = VoltMax/VoltStep;
V = VoltStep*[0:VSD VSD-1:-1:-VSD -VSD+1:-1 0]; V will be a 1x161 matrix
T=1:1:161;
Vt=string(V);
surf(T, FreqS, QualityFactor)
xticklabels({Vt(1),Vt(41),Vt(81),Vt(121),Vt(161)})
0 commentaires
Réponse acceptée
Voss
le 31 Oct 2022
Set the xticks when you set the xticklabels (xticklabels by itself doesn't set the locations of the ticks, just their labels). And probably set the xlim as well.
VoltMax = 200;
VoltStep = 5;
VSD = VoltMax/VoltStep;
V = VoltStep*[0:VSD VSD-1:-1:-VSD -VSD+1:-1 0];
T=1:1:161;
surf(T, linspace(0,20,200), rand(200,161)) % random data for demo
xticks(T(1:VSD:end))
xticklabels(string(V(1:VSD:end)))
xlim(T([1 end]))
view(2)
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!