I am using pgfplot to draw graphs in latex. Now this is the problem I am facing:

\begin{axis}[ybar,grid=major,bar width=2pt,width=8cm, height=8cm,xmin=1,xmax=540,ymin=1,ymax=240]
 table [x=size, y=cluster, col sep=comma] {sim-0.4-0.6.csv};

It generates the following graph:

enter image description here

Since, I have values mainly between 0-50 on x-axis, I want to zoom there. After that, values comes around 500. S0, there are no graph points between 50 - 450. How should I do that?


2 Answers 2


I found a workaround approach here and adapted it a little so it would look more like your request.

This is certainly not perfect, since you have to substract an offest from your data and are tweeking it a lot. As I needed something like that before at some point I still think it's okay to do it like this since the x discontinuity feature doesn't allow you to insert the break at an arbitrary position rather than just next to the other axis.

edit: Fiddled some more with the extra x tick labels and added negative spacing to reduce the size of the white box. The result looks better now, the way to do it isn't though.

    xtick distance =10,
    extra x ticks={60},
    extra x tick style={tick label style={yshift=1.6em}},
    extra x tick labels={\colorbox{white}{$ \mkern-14mu||\mkern-8mu$}}
\addplot+[draw=black,fill=green] table { 
    x y
    10 11
    20 15
    50 20
\addplot+[draw=black,fill=green] table[x expr=\thisrow{x}-430,] {
    x y
    530 25
    520 15
    500 10



Besides simulating a discontinuous axis you could also draw an inset plot which shows only a ("zoomed") part of the plot.

For more details on how the solution works, please have a look at the comments in the code.

(Please note that I have created a dummy function to show some data, because the CSV file was not available when writing this answer.)

% used PGFPlots v1.14
        % enlare the axis limits
        % (as it was requested in your other question
        %  <http://tex.stackexchange.com/q/358199>)
        % I use this so it easier to set the two plots in a good ratio
        % (because then the labels don't count to the `width' and `height')
        scale only axis,
        % now list the options that are in common for both plots
        table/col sep=comma,
        % these options are only for the dummy data, since the CSV file was not
        % available when writing this answer
    % declare some layers and their order
    % these are needed if you want to have a background (color) behind the whole
    % inset plot (including the `ticklabels' etc.) and not only the background
    % of the "box" of the inset plot.
    % You want to do at least one of these to avoid that also in the inset plot
    % the grid lines of the "main" plot are shown/visible
    % on the "lowest" layer, draw the normal plot
%        % if you really want to "cut off" some data, you can do this with this
%        % key
%        restrict x to domain=1:1000,
%        \addplot [mark=x] table [x=size, y=cluster] {sim-0.3-0.6.csv};
        % just a dummy function to produce a plot
        \addplot {250*exp(-x/10)};

        % store a coordinate where the inset should be plotted at
        \coordinate (inset) at (axis description cs:0.95,0.95);

    % the inset plot should be plotted on the "top" most layer
    % this is the inset plot ...
        % ... which should be plotted at the stored coordinate ...
        % ... with this `anchor'
        anchor=north east,
        % use this predefined style (it is predefined by PGFPlots itself)
        % now state the options which should be used for the inset plot
        % use this key to fill the background of the axis only
        axis background/.style={
        % name this axis so it can later be used to fill the "background" of the
        % whole plot including the labels
%        \addplot [mark=x] table [x=size, y=cluster] {sim-0.3-0.6.csv};
        % again the dummy plot
        \addplot {250*exp(-x/10)};

    % on the "medium" layer we draw the background of the whole inset plot
    % including the labels
        % (I fill it with a gray here, so one can see the difference to the
        %  `axis background' result in the inset plot itself)
        \fill [black!10] ([shift={(-2pt,-2pt)}] insetAxis.outer south west)
            rectangle    ([shift={(+5pt,+5pt)}] insetAxis.outer north east);

image showing the result of above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .