Draw a scatter plot

From CodeCodex

Related content:

The code examples below show how to draw a scatter plot.

Online casinos offer bonuses to attract players and also to make the participation livelierand encourage the player to invest more. Many sites offer the sign up bonuses that is a percentage (generally 100%) of the first deposit and the players are also offered bonuses on subsequent play. The casino bonus are also helpful in marketing of the site and also attract new players who can play more if satisfied.

Visit Palace casino,for a very enjoyable, gambling and gaming experience, the smoke free hotel offers great service and food that is loved by all. If you love slots then you will definitely enjoy playing the game and have great winnings.

Free online blackjack is offered in almost all the casinos online, you can play the game free and enhance your skills before playing for real money in a casino.

If you are unfamiliar with the rules of casino blackjack or simply need some clarification on the finer points, then play blackjack free online and get familiar with the various odds and rules.

Play free casino slot and get the confidence to join the progressive jackpots and professional tournament plays to win great from the game.

Shops for Cheap poker tables online, of different shapes, made with different materials and along with different features, compare the costs easily and find a higher variety to choose from.

The royal casino online offers you over 3000 online games that are free to download, including flash games , internet casino games , gambling games and various other games to best enjoy.

A poker tournament is a tournament where players compete by playing poker. It can feature as few as two players or numerous players playing on a single table.

Winstar casino offers a world of luxury, excitement and entertainment. It features the best in casino games and offers daily, weekly and monthly poker tournaments and also offer great promotions to take advantage of.

River rock casino in northern California features slot machines, table games, casino games, and a variety of dining options with live entertainment, shows and events. It is a certified 4 star casino in the Alexander valley.

Visit the choctaw casino that is a premiere Oklahoma casino, and is an ultimate destination for Poker, Blackjack and slots, you can also have the best of entertainment at the live shows and events and have the best accommodations and hospitality.


Casino bonuses no deposit are a great way of trying a casino without risking your own cash. These bonuses are free money to play a variety of casino games in real.

free online roulette

Internet roulette is the virtual form of the traditional game, it offers great variety of bonuses, offers and betting choices and latest features compared to the traditional game.

Play Video poker games a combination of poker and slots on a computerized console similar in size to a slot machine,

Free poker tournaments allow to you get the grasp of the professional level tournament plays for free, and if you have the skill you can also win some hundreds of dollars in winning for free form these games.

Play the best Video poker free online, to know the pros and get used to the plays that will help you beat the game and win great.

Poker, blackjacks are some of the popular casino card games, these games are easily available online with exclusives bonus and free plays offers.

If you are new and confused about operating the slots machine then the free casino slot games are best for you, you can develop the confidence to operate these magical slot machines with no risk.

Find the best no deposit casino bonuses from the reviews sites that offer the list of some of the best casino bonuses available for gamblers to make most of.

Visit a reputable and genuine reviews site to know the latest no deposit casino bonuses, you will find the best and most exclusive bonuses available at your fingertips.

The aim of every poker player on the poker table is to arrange the Best poker hands order to win the pot, there are various strategies that will help you get the highest hands order.

888 Casino Review rate the site as one of the most secure and most trusted poker sites online, it offers exclusive bonuses on first deposit and on subsequent plays

Join the Blackjack online free play to be able to face the game with confidence and be a successful winner at the money plays

Texas casino offers betting in various baseball and football matches, horse races and different types of casino games.

Go for Poker real money and win big and join the professional tournament and jackpot and grab the chance to win millions form the poker game

To help the plays get associated with the right casino company that tis best suitable for themselves the online casino reviews are available, these are unbiased and genuine reviews about the casino company that can be a basis of numerous decisions.

Rivers Casino coupons can save players money on their gambling expenses; these coupons offer great discounts, promotional deals, the details of which can be found on the home page of the site.

Three rivers casino offers, slots, blackjacks and other table games, there are three restaurants, live concerts and events for your entertainment and great accommodations for you to have an exciting and comfortable time in Florence, United States.

The Casino for iphone features the best casino games, like Blackjack, Roulette, Slots, Baccarat, Video Poker & Keno, that can be conveniently enjoyed while relaxing and even on the go.

Download the application and enjoy the online casino ipad and have a great gambling experience on the go, but make sure you read the reviews and get customer ratings before downloading.

Android casino games are quiet popular since 2005, Android made its way big in no time. Almost all mobile casino rooms can easily be accessed using Android devices, giving the players a chance to enjoy playing their favourite games wherever and whenever.

When it comes to mobile casino games, most of the time you are eager to play and enjoy some of your favourite ones, like slots and table games, card games that you can play on your mobile device or tablet.

If you are a freebee then there are free mobile casino games available for you to enjoy and have fun, practice the game and try out the play of your favourite casino game before you invest in it.

You will always cherish your mobile game plays, claiming the wide variety of free mobile casino bonus; these bonuses give a boost to your bankroll and are also agreat marketing trick.

Play online casino real money jackpot plays and grab a chance to win thousands of dollars, or simply join the money plays and win huge bonuses.

Go Real money casino game of your favourite casino game, but make sure you do your research and get associated to a genuine company and access the best offers and bonuses available.

Sports Betting Online offer you up to date news, reviews, bonuses, information on the best sports-books, you can also wager at your favourite sports game online and win great without leaving your comforts.

Gambling online is most common in online casinos, a quick search will reveal you that these online casinos are quiet popular among the gamblers world over.

Gambling online casino has become a lot popular, to be a successful gambler you need to know the gambling laws the rules of the gambling games, the strategies to be a successful and have the best of gambling experience.

If you love the game and like to wager at it them the football gambling online offered at reputable sites is for you, now wager at your favourite team and built up the match excitement to the nest lever by investing in it.

The android casino apps are easily available online, to be downloaded free of charge, but one need not ensure that you download it form a genuine company, read the reviews and know the detail of the software beforehand to have the best experience.

Casino apps for smart phones, I pads and I phones are available online free to download, you can gamble at your favourite casino game anytime anywhere on the go.

Android casino apps online are offered by most of the companies, owing to their demand, one need to do a fair amount of research and go for a reputable and genuine company for the best deal

Play bingo free online to try the different variations of the game and get used to their plays before you finally decide the one you will be interested in investing.

Bingo game is among the most popular and traditional family fun game, the virtual form of this game with newest variations is available online to enjoy and have fun.

Free bingo game online is offered at almost all the casino companies, the free plays are a way adopted by the companies to attract players and to encourage them to wager.

If your child find difficulty in learning you can seek help of the Bingo games for kids that teach kinds in an interactive manner in play way method.

Bingo game to play are available in massive number at various companies, make sure you do your research and join a genuine company to have a great time gambling.

To be able to handle higher number of bingo cards confidently Play free bingo game online and try hands on its management, the more cards you buy the more chances of winning.

Free bingo games are offered online for players to make most advantage of, these games provide you a snapshot of the real plays, so if you are new to the game you will be able to face them confidently.

Poker is a crucial casino game, it is wise to join the free poker game and try hands on the game before investing in it, in this way you will be able to better understand the odds.

Free online poker games offer you a chance to learn the most lucrative casino game, without any risk, poker games require a lot of patience and practice and what best way to try the game other than the free plays.

Poker is a classic casino game that is most commonly found in casinos online as well as on land, the online casinos offer great plays coupled with the best offers, bonuses, promotions and free money as their overhead costs are lesser comparatively.


Those who like to what sporting events, and generally make right predictions, can now win great from betting in sports. Sports betting is an ideal way to win some free money in free time while enjoying your favourite sport.

Online sports betting is fast, simple and easy. Once you sign up process for you to start betting in minutes. Online bet companies are flexible and offer better and higher odds than the land based companies.

Sky sports football is also offered on mobile, Download Sky Sports by British Sky Broadcasting from BlackBerry Apps in the football and get the latest news even more accessible and keep track on when SKY Sports are showing Live Football over the next month.

Online betting sites allow you to have a great time betting in football games world football leagues, livefootball matches with some of the biggest Sports Betting providers offering higher winnings online.

To have the best free sports bet, it is ideal to spend some time finding the detail of the different free offers available, take advantage of the free casino bonus that is offered to you, and have fun and bet more to win more.

At the sports betting forum you can also meet sports betting fans and some of the recognised names from the industry and betting business or even meet your favourite sports star and winners.

Majority of the individual prefer a sports bet to have some extra income from their passion and knowledge.

You can choose among the different types of bets to wager, generally more people are turning to the Internet for all types of betting on online football games such as sides, totals, parlays, teasers, big game props, and many more.

There are various types of bets offered online to bet in horse racing, football, soccer, tennis, darts, snooker, golf and many more. With a few minutes of reference to the guides and tips offered on online sky sports football, you can get educated about them.

Sports' betting online has gained a lot of popularity, there are various online betting sports that allow more and more people to bet online and have a great time betting.


Implementations[edit]

Java[edit]

2D Plot Applet[edit]

40px

This code requires Java Components for Mathematics, an external library, to run.
/*************************************************************************
*                                                                        *
*  This source code file, and compiled classes derived from it, can      *
*  be used and distributed without restriction, including for commercial *
*  use.  (Attribution is not required but is appreciated.)               * 
*                                                                        *
*   David J. Eck                                                         *
*   Department of Mathematics and Computer Science                       *
*   Hobart and William Smith Colleges                                    *
*   Geneva, New York 14456,   USA                                        *
*   Email: eck@hws.edu          WWW: http://math.hws.edu/eck/            *
*                                                                        *
*************************************************************************/



import edu.hws.jcm.awt.*;
import edu.hws.jcm.data.*;
import edu.hws.jcm.draw.*;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.applet.Applet;

/**
 * A ScatterPlotApplet shows a scatter plot of data from a DataTableInput.
 * The user can enter the data in a two-column table that is shown in
 * the applet.  It is also possible to configure the applet with a menu
 * of file names.  These files, which must be in the same directory as
 * the Web page on which the applet appears, will appear in a menu.
 * A file can contain data for the table, with two numbers per line.
 * When the user loads the file, the data replaces the data in the table.
 */

public class ScatterPlotApplet extends Applet implements ActionListener {

   private Frame frame;       // If non-null, a separate window.
   private String frameTitle; // Title for the separate window.
   private Button launchButton;  // If non-null, then clicking this buttons opens a separate window.
   private String launchButtonName;  // Name for the launch button.
   
   private DataTableInput table;    //  The table for input of data.
   private ScatterPlot scatterPlot; //  The scatter plot of the data.
   private DisplayCanvas canvas;    //  The DisplayCanvas on which the plot is drawn.
   private Button loadFileButton;   //  When clicked, a data file is loaded.
   private Choice fileMenu;         //  Pop-up menu containing names of functions.
   private String[] fileNames;      //  Names of data files associated with menu entries.
   private Controller mainController;  // Controller from the main JCMPanel.

   /**
    * The init() method is called by the system to set up the applet. 
    * If the applet does not appear as a button, then init() creates the main panel of the applet
    * and calls setUpMainPanel to set it up.
    */
   public void init() {
      frameTitle = getParameter("FrameTitle"); // Get title to be used for separate window, if any.
      if (frameTitle == null) {
         frameTitle = "Scatter Plots";
         int pos = frameTitle.lastIndexOf('.');
         if (pos > -1)
            frameTitle =  frameTitle.substring(pos+1);
      }
      setLayout(new BorderLayout());
      int height = getSize().height;
      launchButtonName = getParameter("LaunchButtonName");
      if ( (height > 0 && height <= 50) || launchButtonName != null) {
              // Use a separater window and only show a button in the applet.
          if (launchButtonName == null)
               launchButtonName = "Launch " + frameTitle;
          launchButton = new Button(launchButtonName);
          add(launchButton, BorderLayout.CENTER);
          launchButton.addActionListener(this);
      }
      else {
             // Show the main panel in the applet, not in a separate window.
          add(makeMainPanel(), BorderLayout.CENTER);
      }
   }

   /*
    * Create the main panel of the applet.
    */ 
   public Panel makeMainPanel() {
   
      // Make the main panel
   
      JCMPanel panel = new JCMPanel(2);
      mainController = panel.getController();
      panel.setBackground(new Color(0,0,180));
      panel.setInsetGap(2);
      setLayout(new BorderLayout());
      
      // Make a DataInputTable with two columns
      
      table = new DataTableInput(null, 2);
      table.setColumnName(0, getParameter("ColumnName1", "X"));
      table.setColumnName(1, getParameter("ColumnName2", "Y"));
      table.setThrowErrors(true);
      if ( "yes".equalsIgnoreCase(getParameter("ShowColumnTitles","yes")))
         table.setShowColumnTitles(true);
      if ( "yes".equalsIgnoreCase(getParameter("ShowRowNumbers","yes")))
         table.setShowRowNumbers(true);
                                 
      // Make input boxes for getting expressions that can include
      // the variables associated with the table.  Initially, the 
      // expressions are just the column names.

      Parser parser = new Parser();
      table.addVariablesToParser(parser);
      ExpressionInput input1 = new ExpressionInput(table.getColumnName(0),parser);
      input1.setOnUserAction(mainController);
      ExpressionInput input2 = new ExpressionInput(table.getColumnName(1),parser);
      input2.setOnUserAction(mainController);
      
      // Make a scatter plot that graphs the first expressiong vs. the second expression.

      scatterPlot = new ScatterPlot(table, input1.getExpression(), input2.getExpression());
      if ( ! "yes".equalsIgnoreCase(getParameter("ShowRegressionLine","yes")))
        scatterPlot.setShowRegressionLine(false);
      if ( ! "yes".equalsIgnoreCase(getParameter("MissingValueIsError","yes")))
        scatterPlot.setMissingValueIsError(false);
        
      // Create the display canvas where the scater plot will be shown.

      canvas = new DisplayCanvas();
      canvas.add(new Axes());
      canvas.add(scatterPlot);
      mainController.setErrorReporter(canvas);
      
      // A compute button to recompute everything.
      
      ComputeButton computeButton = new ComputeButton("Update Display");
      computeButton.setOnUserAction(mainController);
      computeButton.setBackground(Color.lightGray);
      
      // A menu of files that can be loaded.  If no filenames are provided as
      // applet parameters, then menu is null.
      
      Panel menu = makefileMenu();
      
      // Lay out the components in the applet.
      
      JCMPanel inputPanel = null;
      Panel bottom = null;  //might not be a JCMPanel
      if ( "yes".equalsIgnoreCase(getParameter("UseExpressionInputs","yes"))) {
         inputPanel = new JCMPanel(1,2);
         inputPanel.setBackground(Color.lightGray);
         JCMPanel leftInput = new JCMPanel();
         leftInput.add(new Label("  Plot:  "), BorderLayout.WEST);
         leftInput.add(input1, BorderLayout.CENTER);
         inputPanel.add(leftInput);
         JCMPanel rightInput = new JCMPanel();
         rightInput.add(new Label(" versus: "), BorderLayout.WEST);
         rightInput.add(input2, BorderLayout.CENTER);
         inputPanel.add(rightInput);
         bottom = new JCMPanel(new BorderLayout(12,3));
         bottom.add(inputPanel, BorderLayout.CENTER);
         bottom.add(computeButton, BorderLayout.EAST);
      }
      
      if ( scatterPlot.getShowRegressionLine() && "yes".equalsIgnoreCase(getParameter("ShowStats","yes")) ) {
            // Make a display label to show some statistics about the data.
         DisplayLabel dl = new DisplayLabel(
               "Slope = #;  Intercept = #;  Correlation = #",
                new Value[] { scatterPlot.getValueObject(ScatterPlot.SLOPE), 
                              scatterPlot.getValueObject(ScatterPlot.INTERCEPT), 
                              scatterPlot.getValueObject(ScatterPlot.CORRELATION) }
            );
         dl.setAlignment(Label.CENTER);
         dl.setBackground(Color.lightGray);
         dl.setForeground(new Color(200,0,0));
         dl.setFont(new Font("Serif",Font.PLAIN,14));
         if (bottom != null) 
            bottom.add(dl, BorderLayout.SOUTH);
         else {
            bottom = new JCMPanel(new BorderLayout(12,3));
            bottom.add(dl, BorderLayout.CENTER);
            bottom.add(computeButton, BorderLayout.EAST);
         }
      }
      
      if (bottom == null) {
         if (menu != null)
            menu.add(computeButton, BorderLayout.EAST);
         else {
            bottom = new Panel();
            bottom.add(computeButton);
         }
      }
      
      panel.add(canvas, BorderLayout.CENTER);
      panel.add(table, BorderLayout.WEST);
      if (bottom != null)
         panel.add(bottom, BorderLayout.SOUTH);
      if (menu != null)
         panel.add(menu, BorderLayout.NORTH);
      else {
         String title = getParameter("PanelTitle");
         if (title != null) {
            Label pt = new Label(title, Label.CENTER);
            pt.setBackground(Color.lightGray);
            pt.setForeground(new Color(200,0,0));
            pt.setFont(new Font("Serif",Font.PLAIN,14));
            panel.add(pt, BorderLayout.NORTH);
         }
      }
         
      return panel;
      
   } // end makeMainPanel()
   
   
   private Panel makefileMenu() {
         // If the applet tag contains params named "File", "File1", "File2", ..., use
         // their values to make a file menu.  If the value of the param contains a ";",
         // then the first part, up to the ";", goes into the menu and the second part
         // is the name of the file.  If there is no ";", then the entire value is
         // shown in the menu and is also used as the name of the file.  The actual
         // files must be in the same directory as the Web page that contains the applet.
      List<String> names = new ArrayList<String>();
      fileMenu = new Choice();
      String file = getParameter("File");
      int ct = 1;
      if (file == null) {
         file = getParameter("File1");
         ct = 2;
      }
      while (file != null) {
         file = file.trim();
         int pos = file.indexOf(";");
         String menuEntry;
         if (pos == -1)
            menuEntry = file;
         else {
            menuEntry = file.substring(0,pos).trim();
            file = file.substring(pos+1).trim();
         }
         names.add(file);
         fileMenu.add(menuEntry);
         file = getParameter("File" + ct);
         ct++;
      }
      if (names.isEmpty()) {
         fileMenu = null;
         return null;
      }
      else {
         fileNames  = names.toArray(new String[0]);
         Panel p = new Panel();
         p.setBackground(Color.lightGray);
         p.setLayout(new BorderLayout(5,5));
         p.add(fileMenu,BorderLayout.CENTER);
         loadFileButton = new Button("Load Data File: ");
         loadFileButton.addActionListener(this);
         p.add(loadFileButton,BorderLayout.WEST);
         fileMenu.setBackground(Color.white);
         return p;
      }
   }
   
   private void doLoadFile(String name) {
        // Load the file from the same directory as the Web page and put the data
        // from the file into the table.  The file should contain two numbers on
        // each line.
      InputStream in;
      try {
         URL url = new URL(getDocumentBase(), name);
         in = url.openStream();
      }
      catch (Exception e) {
         canvas.setErrorMessage(null,"Unable to open file named \"" + name + "\": " + e);
         return;
      }
      Reader inputReader = new InputStreamReader(in);
      try {
         table.readFromStream(inputReader);
         inputReader.close();
      }
      catch (Exception e) {
         canvas.setErrorMessage(null,"Unable to get data from file \"" + name + "\": " + e.getMessage());
         return;
      }
      mainController.compute();
   }

   /**
    *  Respond when user clicks a button; not meant to be called directly.
    *  This opens and closes the separate window.
    */ 
   synchronized public void actionPerformed(ActionEvent evt) {
      Object source = evt.getSource();
      if (loadFileButton != null && source == loadFileButton) {
         doLoadFile( fileNames[fileMenu.getSelectedIndex()] );
      }
      else if (source == launchButton && launchButton != null) {
            // Open or close separate frame.
         launchButton.setEnabled(false);
         if (frame == null) {
            frame = new Frame(frameTitle);
            frame.add(makeMainPanel());
            frame.addWindowListener( new WindowAdapter() {
                  public void windowClosing(WindowEvent evt) {
                     frame.dispose();
                  }
                  public void windowClosed(WindowEvent evt) {
                     frameClosed();
                  }
               } );
            frame.pack();
            frame.setLocation(50,50);
            frame.show();
            launchButton.setLabel("Close Window");
            launchButton.setEnabled(true);
         }
         else {
            frame.dispose();
         }
      }
   }
   
   synchronized private void frameClosed() {
        // respond when separate window closes.
      frame = null;
      launchButton.setLabel(launchButtonName);
      launchButton.setEnabled(true);
   }
   
   /**
    *  Return the applet parameter with a given param name, but if no
    *  such applet param exists, return a default value instead.
    */
   protected String getParameter(String paramName, String defaultValue) {
       String val = getParameter(paramName);
       return (val == null)? defaultValue : val;
   }
   
} // end class ScatterPlotApplet

3D Plot Applet[edit]

40px

This code requires JMathTools, an external library, to run.
  package org.math.examples; 
  import java.applet.*; 
  import org.math.plot.*;
  
  /**
   * Copyright : BSD License
   * @author Yann RICHET
   */
  
  public class Plot3DApplet extends Applet {
  
    public void init() {
      // Data definition
      int n = 10;
      double[][] data"datas1" = new double[n][3];
      double[][] data"datas2" = new double[n][3];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
          data"datas1"[i][j] = Math.random();
          data"datas2"[i][j] = Math.random();
        }
      }
  
      // PlotPanel construction
      Plot3DPanel plotpanel = new Plot3DPanel();
      plotpanel.addLegend("SOUTH");
  
      // Data plots addition
      plotpanel.addScatterPlot("datas1", data"datas1");
      plotpanel.addBarPlot("datas2", data"datas2");
  
      // include plot in applet
      add(plotpanel);
    }
  }

OCaml[edit]

Using xmgrace via mlgrace:

# open Grace;;
# let gv = new grace_view ~layout:(`Size (650, 500)) ();;
val gv : Grace.grace_view = <obj>
# let rand() = Array.init 1000 (fun _ -> Random.float 1.);;
val rand : unit -> float array = <fun>
# gv#plot ~linestyle:0 ~symbol:1 (rand()) (rand());;
- : unit = ()
# gv#redraw ();;
- : unit = ()

Using PLplot, based on the mlgrace example:

open Plplot
let rand () = Array.init 1000 (fun _ -> Random.float 1.0) in
Quick_plot.points [rand (), rand ()]

Perl[edit]

use Chart::Plot qw();
my $img = Chart::Plot->new;
my @data = qw( -3 9   -2 4   -1 1   0 0   1 1  2 4  3 9);
$img->setData(\@data, 'noline'); # no lines = scatter plot
$img->draw; # returns binary PNG data

Tcl[edit]

package require Plotchart

canvas .c -background white -width 400 -height 200
pack   .c -fill both

set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
foreach {x y} {0.0 32.0 10.0 50.0 25.0 60.0 78.0 11.0 } {$s plot series1 $x $y}
$s title "Scatter plot"

Related Links:[edit]


Casino employment offer the candidates, world-class 24-hour, non-stop entertainment, at the gambling games, the fine dine restaurants with legendary night life, and is definitely an exciting career with great opportunity.


The Atlantic City casinos offer casino games, hotel accommodations, entertainment, recreation and meeting space for a great entertainment and relaxation time.


Casino Niagara Falls offers everything you need for spending a luxurious evening at the casino. Relax, enjoy, and have a great time at the casino while enjoying your favourite casino game.


The poker Texas Holdem plays are popular work over, every poker plays dreams of winning the game at least once, it is the most popular among the different poker variants.


Casino on internet offer gambling conveniently to its enthusiasts, who were unable to enjoy gambling due to the distance being a barrier.


Blackjack for free teaches you blackjack strategy while you play, joining these games are the best way to try hands on the game and be a successful gambler.


The game blackjack offers the favourite variations of game online with superb graphics and sounds effects making it a livelier experience.


Play blackjack in casino online conveniently, and also avail the chance to win big by joining the professional and tournament plays.


Casino gaming and gambling is best suitable for you if you have a busy schedule or distance is a barrier for you visit the casino. Casino online offer you the traditional as well as the newest variations at the comfort of your home.


Casino rooms are the virtual rooms were the player join the casino plays, to enter the casino room of the casino company you need to register at it, you can join these rooms to enjoy the free as well as money plays.