vDataFrame.scatter

In [ ]:
vDataFrame.scatter(columns: list,
                   catcol: str = "",
                   max_cardinality: int = 3,
                   cat_priority: list = [],
                   with_others: bool = True,
                   max_nb_points: int = 20000,
                   dimensions: tuple = None,
                   bbox: list = [],
                   img: str = "",
                   ax=None,
                   **style_kwds,)

Draws the scatter plot of the input vcolumns.

Parameters

Name Type Optional Description
columns
list
List of two or three vColumns.
catcol
str
Categorical vColumn for labeling the data.
max_cardinality
int
Maximum number of distinct elements for 'catcol' to be used as categorical. The less frequent elements will be gathered together to create a new category: 'Others'.
cat_priority
list
List of the different categories to consider when labeling the data using the 'catcol' vColumn. The other categories will be filtered.
with_others
bool
If set to false and the cardinality of the vColumn 'catcol' is too big, then the less frequent elements will not be merged to another category and these elements will not be drawn.
max_nb_points
int
Maximum number of points to display.
dimensions
tuple
Tuple of two elements representing the IDs of the PCA's components. If empty and the number of input columns is greater than three, the first and second PCA will be drawn.
bbox
list
List of four elements to delimit the boundaries of the final plot. This list must be formatted like: [xmin, xmax, ymin, ymax]
img
str
Path to the background image.
ax
Matplotlib axes object
The axes to plot on.
**style_kwds
any
Any optional parameter to pass to the Matplotlib functions.

Returns

ax : Matplotlib axes object

Example

In [1]:
from verticapy.datasets import load_iris
iris = load_iris()
display(iris)
123
SepalLengthCm
Numeric(5,2)
123
SepalWidthCm
Numeric(5,2)
123
PetalLengthCm
Numeric(5,2)
123
PetalWidthCm
Numeric(5,2)
Abc
Species
Varchar(30)
14.33.01.10.1Iris-setosa
24.42.91.40.2Iris-setosa
34.43.01.30.2Iris-setosa
44.43.21.30.2Iris-setosa
54.52.31.30.3Iris-setosa
64.63.11.50.2Iris-setosa
74.63.21.40.2Iris-setosa
84.63.41.40.3Iris-setosa
94.63.61.00.2Iris-setosa
104.73.21.30.2Iris-setosa
114.73.21.60.2Iris-setosa
124.83.01.40.1Iris-setosa
134.83.01.40.3Iris-setosa
144.83.11.60.2Iris-setosa
154.83.41.60.2Iris-setosa
164.83.41.90.2Iris-setosa
174.92.43.31.0Iris-versicolor
184.92.54.51.7Iris-virginica
194.93.01.40.2Iris-setosa
204.93.11.50.1Iris-setosa
214.93.11.50.1Iris-setosa
224.93.11.50.1Iris-setosa
235.02.03.51.0Iris-versicolor
245.02.33.31.0Iris-versicolor
255.03.01.60.2Iris-setosa
265.03.21.20.2Iris-setosa
275.03.31.40.2Iris-setosa
285.03.41.50.2Iris-setosa
295.03.41.60.4Iris-setosa
305.03.51.30.3Iris-setosa
315.03.51.60.6Iris-setosa
325.03.61.40.2Iris-setosa
335.12.53.01.1Iris-versicolor
345.13.31.70.5Iris-setosa
355.13.41.50.2Iris-setosa
365.13.51.40.2Iris-setosa
375.13.51.40.3Iris-setosa
385.13.71.50.4Iris-setosa
395.13.81.50.3Iris-setosa
405.13.81.60.2Iris-setosa
415.13.81.90.4Iris-setosa
425.22.73.91.4Iris-versicolor
435.23.41.40.2Iris-setosa
445.23.51.50.2Iris-setosa
455.24.11.50.1Iris-setosa
465.33.71.50.2Iris-setosa
475.43.04.51.5Iris-versicolor
485.43.41.50.4Iris-setosa
495.43.41.70.2Iris-setosa
505.43.71.50.2Iris-setosa
515.43.91.30.4Iris-setosa
525.43.91.70.4Iris-setosa
535.52.34.01.3Iris-versicolor
545.52.43.71.0Iris-versicolor
555.52.43.81.1Iris-versicolor
565.52.54.01.3Iris-versicolor
575.52.64.41.2Iris-versicolor
585.53.51.30.2Iris-setosa
595.54.21.40.2Iris-setosa
605.62.53.91.1Iris-versicolor
615.62.74.21.3Iris-versicolor
625.62.84.92.0Iris-virginica
635.62.93.61.3Iris-versicolor
645.63.04.11.3Iris-versicolor
655.63.04.51.5Iris-versicolor
665.72.55.02.0Iris-virginica
675.72.63.51.0Iris-versicolor
685.72.84.11.3Iris-versicolor
695.72.84.51.3Iris-versicolor
705.72.94.21.3Iris-versicolor
715.73.04.21.2Iris-versicolor
725.73.81.70.3Iris-setosa
735.74.41.50.4Iris-setosa
745.82.64.01.2Iris-versicolor
755.82.73.91.2Iris-versicolor
765.82.74.11.0Iris-versicolor
775.82.75.11.9Iris-virginica
785.82.75.11.9Iris-virginica
795.82.85.12.4Iris-virginica
805.84.01.20.2Iris-setosa
815.93.04.21.5Iris-versicolor
825.93.05.11.8Iris-virginica
835.93.24.81.8Iris-versicolor
846.02.24.01.0Iris-versicolor
856.02.25.01.5Iris-virginica
866.02.75.11.6Iris-versicolor
876.02.94.51.5Iris-versicolor
886.03.04.81.8Iris-virginica
896.03.44.51.6Iris-versicolor
906.12.65.61.4Iris-virginica
916.12.84.01.3Iris-versicolor
926.12.84.71.2Iris-versicolor
936.12.94.71.4Iris-versicolor
946.13.04.61.4Iris-versicolor
956.13.04.91.8Iris-virginica
966.22.24.51.5Iris-versicolor
976.22.84.81.8Iris-virginica
986.22.94.31.3Iris-versicolor
996.23.45.42.3Iris-virginica
1006.32.34.41.3Iris-versicolor
Rows: 1-100 | Columns: 5
In [2]:
iris.scatter(["SepalWidthCm", "SepalLengthCm"])
Out[2]:
<AxesSubplot:xlabel='"SepalWidthCm"', ylabel='"SepalLengthCm"'>
In [3]:
# 2D Scatter Plot with catcol
iris.scatter(["PetalWidthCm", "PetalLengthCm"], 
             catcol = "Species")
Out[3]:
<AxesSubplot:xlabel='"PetalWidthCm"', ylabel='"PetalLengthCm"'>
In [4]:
# 3D Scatter Plot
iris.scatter(["PetalWidthCm", "PetalLengthCm", "SepalLengthCm"], 
             catcol = "Species")
Out[4]:
<Axes3DSubplot:xlabel='"PetalWidthCm"', ylabel='"PetalLengthCm"'>
In [5]:
# Iris setosa vs others
iris.scatter(["PetalWidthCm", "PetalLengthCm"], 
             catcol = "Species",
             cat_priority = ["Iris-setosa"])
Out[5]:
<AxesSubplot:xlabel='"PetalWidthCm"', ylabel='"PetalLengthCm"'>
In [6]:
# Only Iris setosa
iris.scatter(["PetalWidthCm", "PetalLengthCm"], 
             catcol = "Species",
             cat_priority = ["Iris-setosa"],
             with_others = False)
Out[6]:
<AxesSubplot:xlabel='"PetalWidthCm"', ylabel='"PetalLengthCm"'>
In [7]:
from verticapy import *
from verticapy.datasets import load_world

# Africa Dataset
africa = vDataFrame("africa_education")
africa_world = load_world()
africa_world = africa_world[africa_world["continent"] == "Africa"]
ax = africa_world["geometry"].geo_plot(color = "white",
                                       edgecolor='black',)

# displaying schools in Africa
africa.scatter(["lon", "lat"],
               catcol = "country_long",
               ax = ax,
               with_others = False)
Out[7]:
<AxesSubplot:xlabel='"lon"', ylabel='"lat"'>
In [9]:
# Scatter Plot will use PCA when the dimensions is too big
# Drawing PCA components 1 & 2
iris.scatter(["SepalWidthCm", 
              "SepalLengthCm", 
              "PetalLengthCm",
              "PetalWidthCm",])
Out[9]:
<AxesSubplot:xlabel='Dim1 (92.5%)', ylabel='Dim2 (5.3%)'>
In [10]:
# Drawing PCA components 1 & 3
iris.scatter(["SepalWidthCm", 
              "SepalLengthCm", 
              "PetalLengthCm",
              "PetalWidthCm",],
             catcol = "Species",
             dimensions = (1, 3))
Out[10]:
<AxesSubplot:xlabel='Dim1 (92.5%)', ylabel='Dim3 (1.7%)'>

See Also

vDataFrame.pivot_table Draws the pivot table of vColumns based on an aggregation.