# Elementary scatter plot of data points

# matplotlib.pyplot.scatter takes parameters:
#  -- lists of x and y coordinates of data points
#  -- size of data points in the plot  (optional)
#  -- colors of data points in the plot  (optional)
#  -- more optional parameters, for details see
#       https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.scatter.html
#
# Size can be specified by a single value which applies to all data points
# or size can be specified for each data point separately
# by a list of sizes (same length as the lists of x and y coordinates).
# color(s) can be specified in the same way as the size(s), either by a single value
# applied to all data points or by a list of values for each separate data point.

# documentation: https://matplotlib.org/3.5.0/index.html

import matplotlib.pyplot as plt
import random

# basic scatter plot using all defaults
def scatter1 ( x, y ):
    plt.title( "PGE example plot\n default display parameters" )
    plt.xlabel( "x-values" )
    plt.ylabel( "y-values" )
    plt.scatter( x, y, label = 'ourLabel' )
    plt.legend( )
    plt.show()

# basic scatter plot with size specifications
def scatter2 ( x, y, pointSizes ):
    plt.title( "PGE example plot\n  point sizes specified" )
    plt.xlabel( "x-values" )
    plt.ylabel( "y-values" )

    plt.scatter( x, y, s = pointSizes )
    plt.show()

# basic scatter plot with size and color specifications
def scatter3 ( x, y, pointSizes, pointColors ):
    plt.title( "PGE example plot\n -point sizes and colors specified" )
    plt.xlabel( "x-values" )
    plt.ylabel( "y-values" )

    plt.scatter( x, y, s = pointSizes, c = pointColors )
    plt.show()

# ----------------------------------------------------------------------
#              E X A M P L E S
# ----------------------------------------------------------------------
# modify the examples and run the code to see the effect(s)

# -------------------------------
# define points, sizes and colors

# use random values for demonstration purposes
def rnd_color():
    return [ random.random(), random.random(), random.random() ]

def rnd_data( n ):
    x = random.sample( range(1, 99), n )
    y = random.sample( range(1, 99), n )
    sizes = random.sample( range(100, 1000), n )
    colors = [ '#ff00ff' ] * n
    colors = [ rnd_color() for i in range(n) ]
    return x, y, sizes, colors

# or specify your own data values
x = [2, 4, 6, 9]
y = [3, 8, 7, 5]
sizes = [400, 900, 100, 1100]
colors = [ '#ff00ff', '#0088ff', '#888800',  '#888888' ]

x, y , sizes, colors = rnd_data( 30 )

# ------------------------------------------------------------
# plot the data points, optionally specifying sizes and colors

# default data points sizes and colors
scatter1( x, y )
# specify data sizes
scatter2( x, y, 1600 )
# specify data sizes for each point separately
scatter2( x, y, sizes )
# specify data sizes and colors
scatter3( x, y, 1600, '#00ff00' )
# specify data sizes and colors for each point separately
scatter3( x, y, sizes, colors )

