banner



How To Add Secondary X Axis In Matlab

As illustrated in the answer from Dennis, you could brand use of some undocumented features to add an actress axis. This has a few drawbacks, the obvious being that undocumented features have a tendency to change without find. Additionally, adding an extra 10 or y axis in the same fashion (i.e. on the opposite side) would cause it to be occluded by the plot and not be very useful. Achieving an effect where the axes are stacked upwardly on one side, equally the answers to this question illustrate, would exist more than desirable in 3D. Even so, this could be somewhat cluttered, and I have yet to find a robust manner to do this that plays well with changes in the plot (i.e. rotation, zooming, irresolute limits, etc).

Instead of calculation some other axis line, a more compact solution that doesn't depend on undocumented features would be to piggyback on an existing centrality' tick marks and simply add an additional set of tick labels at a new scale. The additional set of tick (and centrality) labels tin be colored using TeX markup to differentiate them.

I wrapped some code into a prototype office that does this. The inputs are the axes handle, a cord ('Ten', 'Y', or 'Z') for the axes to modify, a new set of axis limits for the new scale (which will be mapped to the current limits), the color of the new labels (equally an RGB triple), and a string for the new axis characterization:

          function add_scale(hAxes, axisStr, newLimits, newColor, newLabel)    % Get axis ruler to modify:   axisStr = upper(axisStr);   hRuler = get(hAxes, [axisStr 'Centrality']);    % Create TeX colour modification strings:   labelColor = ['\color[rgb]{' sprintf('%f ', hRuler.Label.Color) '}'];   tickColor = ['\color[rgb]{' sprintf('%f ', hRuler.Color) '}'];   newColor = ['\colour[rgb]{' sprintf('%f ', newColor) '}'];    % Compute tick values for new axis scale:   tickValues = hRuler.TickValues;   limits = hRuler.Limits;   newValues = newLimits(1)+...               diff(newLimits).*(tickValues-limits(one))./diff(limits);    % Create new tick labels:   formatString = ['\' tickColor hRuler.TickLabelFormat '\\newline\' ...                   newColor hRuler.TickLabelFormat '\n'];   newTicks = strsplit(sprintf(formatString, [tickValues; newValues]), '\n');    % Update tick and axis labels:   hRuler.Label.String = {[labelColor hRuler.Label.String]; ...                          [newColor newLabel]};   hRuler.TickLabels = newTicks(1:(end-1));  end                  

And hither'due south an instance:

          [X, Y, Z] = peaks(25); hSurf = surfc(Z); hAxes = gca; ylabel('Distance (inches)'); add_scale(hAxes, 'Y', hAxes.YLim.*2.54, [1 0 0], 'Distance (cm)');                  

enter image description here

The new tick labels (in red) are added beneath the existing tick labels, as is the new axis characterization. It may be possible to create listeners to update the new labels automatically (such as when tick marks are changed), but I oasis't worked out all the details of this yet.

How To Add Secondary X Axis In Matlab,

Source: https://stackoverflow.com/questions/43867635/secondary-y-axis-in-matlab-3d-plot-surf-mesh-surfc

Posted by: isaacslact1943.blogspot.com

0 Response to "How To Add Secondary X Axis In Matlab"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel