1

I am trying to break the y-axis of a plot and put Infinity as my top point, but I can't seem to modify the y-axis labels. Ideally, I'd also like to get rid of that curve ~ line that breaks the plot and instead use the double slashes //, but I tried using a bunch of the break axis functions on the matlab file exchange and I couldn't get them to work for me. However, I'd really also like to be able to compare the look of both methods, so I'd like to be able to see how both ways would look.

I want to replace the "600" in the figure below with the word "Infinity" on a broken axis..

I'm using the function breakyaxis.m

Here is my code:

close all;
clc;

figure
% Plot 
 hold on; plot([0 .2 .5 .8 1],[-10 0 50 100 300],'.','MarkerSize',10); %(:,exp_width)); hold on;
plot(.4,150,'+','MarkerSize',10,'MarkerFaceColor','black');
plot(1,600,'+','MarkerSize',10,'MarkerFaceColor','black'); % Set 600 as point where y value should really be infinity

breakyaxis([350 550]); % Break Axis
xlabel('X Axis'); ylabel('Y Axis');
set(gca,'yticklabel',sprintf('%10s',[num2str(-10) num2str(0) num2str(100) 'inf']));
hold off;

Here is a picture of my figure at the moment: plot

Veridian
  • 3,531
  • 12
  • 46
  • 80
  • So you want a "continuous" axes background ; i.e. white all along and only a // on the y axis to show the break? – Benoit_11 Apr 20 '15 at 23:10
  • That would be okay, my primary desire is to have "infinity" instead of 600 printed at the top – Veridian Apr 20 '15 at 23:18

1 Answers1

1

Looking at the code for the function breakyaxis (type edit breakyaxis in the Command Window) we see that we can actually call the function with an output argument, named breakInfo, which is a structure containing a bunch of information about the 4 axes created in the function.

The axes called highAxes is the one containing the YTickLabel 600, which you want to replace with 'Infinity'.

Therefore, assign an output when calling breakyaxis as follows:

breakInfo = breakyaxis([350 550]);

And add this line:

set(breakInfo.highAxes,'YTicklabel','Infinity')

The plot then looks like this:

enter image description here

Benoit_11
  • 13,905
  • 2
  • 24
  • 35
  • How is this any different from using ylabels = get(gca,'ytick'); ylabels = num2cell(num2str(ylabels.'),2); ylabels([end]) = {'Infinity'}; set(gca,'yticklabel',ylabels); I need this to work with a broken axis. – Veridian Apr 21 '15 at 00:18
  • Oh I misunderstood your question then. I'll remove my answer. – Benoit_11 Apr 21 '15 at 01:11