The class reference for Graph has a SetClipping function. From the documentation:
Enable or disable clipping outside the plot area. If clipping is
enabled then only the part of the graph exactly inside the plot area
will be visible.
Clipping may come in handy when you for example set a manual scale and
have data points outside the specified range.
By default clipping is disabled.
Note 1: Clipping is only supported for graphs at 0 or 90 degrees
rotation and will generate an error message if enabled together with
any other angle.
Note 2: The clipping is implemented with a O(1) algorithm in terns of
data size.
You need to enable clipping by calling the function:
$graph->SetClipping();