--- a/plplot.pd
+++ b/plplot.pd
@@ -1190,6 +1190,9 @@
 ## user-visible routines
 #
 
+# Internal record of what PLplot stream number to associate with the the next new plot object.
+my $next_plplot_stream = 0;
+
 # This routine starts out a plot.  Generally one specifies
 # DEV and FILE (device and output file name) as options.
 sub new {
@@ -1202,6 +1205,11 @@
   $self->{COLORS} = [];
 
   bless $self, $type;
+
+  # set stream number first
+  $self->{STREAMNUMBER} = $next_plplot_stream;
+  $next_plplot_stream++;
+  plsstrm($self->{STREAMNUMBER});
 
   # set background and frame color first
   $self->setparm(BACKGROUND => 'WHITE',
@@ -1255,6 +1263,9 @@
 
   my %opts = @_;
 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+
   # apply all options
  OPTION:
   foreach my $o (keys %opts) {
@@ -1274,6 +1285,9 @@
 
   my %opts = @_;
 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+
   # only process COLORMAP entries once
   my $z = $opts{COLORMAP};
   delete ($opts{COLORMAP});
@@ -1364,6 +1378,9 @@
   my $orientation = shift; # 'v' (for vertical) or 'h' (for horizontal)
 
   my %opts = @_;
+
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
 
   # apply options
   $self->setparm(%opts);
@@ -1450,6 +1467,9 @@
 
   my %opts = @_;
 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+
   # apply options
   $self->setparm(%opts);
 
@@ -1504,6 +1524,9 @@
 
   my %opts = @_;
 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+
   # apply options
   $self->setparm(%opts);
 
@@ -1554,6 +1577,8 @@
   my $maxlab = defined($opts{MAXBARLABELS}) ? $opts{MAXBARLABELS} : 20;
   delete ($opts{MAXBARLABELS});
 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
   my $xmax = scalar(@$labels);
 
   # apply options
@@ -1611,6 +1636,9 @@
   my $self = shift;
   my $text = shift;
 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+
   # apply options
   $self->setparm(@_);
 
@@ -1633,6 +1661,10 @@
 # Clear the current page. This should only be used with interactive devices!
 sub clear {
   my $self = shift;
+
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+
   plclear();
   return;
 }
@@ -1641,6 +1673,9 @@
 sub cursor {
   my $self = shift;
 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+
   # Flush the stream, to make sure the plot is visible & current
   plflush();
 
@@ -1654,6 +1689,10 @@
 # Explicitly close a plot and free the object
 sub close {
   my $self = shift;
+ 
+  # Set PLplot to right output stream
+  plsstrm($self->{STREAMNUMBER});
+ 
   plend1 ();
   return;
 }