Teradata Package for Python Function Reference | 20.00 - plot - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.dataframe.dataframe.DataFrame.plot = plot(self, x, y, scale=None, kind='line', **kwargs)
- DESCRIPTION:
Generate plots on teradataml DataFrame. Following type of plots
are supported, which can be specified using argument "kind":
* bar plot
* corr plot
* line plot
* mesh plot
* scatter plot
* wiggle plot
PARAMETERS:
x:
Required Argument.
Specifies a DataFrame column to use for the x-axis data.
Types: teradataml DataFrame Column
y:
Required Argument.
Specifies DataFrame column(s) to use for the y-axis data.
Types: teradataml DataFrame Column OR list of teradataml DataFrame Columns.
scale:
Optional Argument.
Specifies DataFrame column to use for scale data to
wiggle and mesh plots.
Note:
"scale" is significant for wiggle and mesh plots. Ignored for other
type of plots.
Types: teradataml DataFrame Column.
kind:
Optional Argument.
Specifies the kind of plot.
Permitted Values:
* 'line'
* 'bar'
* 'scatter'
* 'corr'
* 'wiggle'
* 'mesh'
Default Value: line
Types: str
ax:
Optional Argument.
Specifies the axis for the plot.
Types: Axis
cmap:
Optional Argument.
Specifies the name of the colormap to be used for plotting.
Notes:
* Significant only when corresponding type of plot is mesh or geometry.
* Ignored for other type of plots.
Permitted Values:
* All the colormaps mentioned in below URLs are supported.
* https://matplotlib.org/stable/tutorials/colors/colormaps.html
* https://matplotlib.org/cmocean/
Types: str
color:
Optional Argument.
Specifies the color for the plot.
Note:
Hexadecimal color codes are not supported.
Permitted Values:
* 'blue'
* 'orange'
* 'green'
* 'red'
* 'purple'
* 'brown'
* 'pink'
* 'gray'
* 'olive'
* 'cyan'
* Apart from above mentioned colors, the colors mentioned in
https://xkcd.com/color/rgb are also supported.
Default Value: blue
Types: str OR list of str
figure:
Optional Argument.
Specifies the figure for the plot.
Types: Figure
figsize:
Optional Argument.
Specifies the size of the figure in a tuple of 2 elements. First
element represents width of plot image in pixels and second
element represents height of plot image in pixels.
Default Value: (640, 480)
Types: tuple
figtype:
Optional Argument.
Specifies the type of the image to generate.
Permitted Values:
* 'png'
* 'jpg'
* 'svg'
Default Value: png
Types: str
figdpi:
Optional Argument.
Specifies the dots per inch for the plot image.
Note:
* Valid range for "dpi" is: 72 <= width <= 300.
Default Value: 100 for PNG and JPG Type image.
Types: int
grid_color:
Optional Argument.
Specifies the color of the grid.
Note:
Hexadecimal color codes are not supported.
Permitted Values:
* 'blue'
* 'orange'
* 'green'
* 'red'
* 'purple'
* 'brown'
* 'pink'
* 'gray'
* 'olive'
* 'cyan'
* Apart from above mentioned colors, the colors mentioned in
https://xkcd.com/color/rgb are also supported.
Default Value: gray
Types: str
grid_format:
Optional Argument.
Specifies the format for the grid.
Types: str
grid_linestyle:
Optional Argument.
Specifies the line style of the grid.
Permitted Values:
* -
* --
* -.
Default Value: -
Types: str
grid_linewidth:
Optional Argument.
Specifies the line width of the grid.
Note:
Valid range for "grid_linewidth" is: 0.5 <= grid_linewidth <= 10.
Default Value: 0.8
Types: int OR float
heading:
Optional Argument.
Specifies the heading for the plot.
Types: str
legend:
Optional Argument.
Specifies the legend(s) for the Plot.
Types: str OR list of str
legend_style:
Optional Argument.
Specifies the location for legend to display on Plot image. By default,
legend is displayed at upper right corner.
Permitted Values:
* 'upper right'
* 'upper left'
* 'lower right'
* 'lower left'
* 'right'
* 'center left'
* 'center right'
* 'lower center'
* 'upper center'
* 'center'
Default Value: 'upper right'
Types: str
linestyle:
Optional Argument.
Specifies the line style for the plot.
Permitted Values:
* -
* --
* -.
* :
Default Value: -
Types: str OR list of str
linewidth:
Optional Argument.
Specifies the line width for the plot.
Note:
Valid range for "linewidth" is: 0.5 <= linewidth <= 10.
Default Value: 0.8
Types: int OR float OR list of int OR list of float
marker:
Optional Argument.
Specifies the type of the marker to be used.
Permitted Values:
All the markers mentioned in https://matplotlib.org/stable/api/markers_api.html
are supported.
Types: str OR list of str
markersize:
Optional Argument.
Specifies the size of the marker.
Note:
Valid range for "markersize" is: 1 <= markersize <= 20.
Default Value: 6
Types: int OR float OR list of int OR list of float
position:
Optional Argument.
Specifies the position of the axis in the figure. Accepts a tuple
of two elements where first element represents the row and second
element represents column.
Default Value: (1, 1)
Types: tuple
span:
Optional Argument.
Specifies the span of the axis in the figure. Accepts a tuple
of two elements where first element represents the row and second
element represents column.
For Example,
Span of (2, 1) specifies the Axis occupies 2 rows and 1 column
in Figure.
Default Value: (1, 1)
Types: tuple
reverse_xaxis:
Optional Argument.
Specifies whether to reverse tick values on x-axis or not.
Default Value: False
Types: bool
reverse_yaxis:
Optional Argument.
Specifies whether to reverse tick values on y-axis or not.
Default Value: False
Types: bool
series_identifier:
Optional Argument.
Specifies the teradataml DataFrame Column which represents the
identifier for the data. As many plots as distinct "series_identifier"
are generated in a single Axis.
For example:
consider the below data in teradataml DataFrame.
ID x y
0 1 1 1
1 1 2 2
2 2 10 10
3 2 20 20
If "series_identifier" is not specified, simple plot is
generated where every 'y' is plotted against 'x' in a
single plot. However, specifying "series_identifier" as 'ID'
generates two plots in a single axis. One plot is for ID 1
and another plot is for ID 2.
Types: teradataml DataFrame Column.
style:
Optional Argument.
Specifies the color for the plot.
Note:
Hexadecimal color codes are not supported.
Permitted Values:
* 'blue'
* 'orange'
* 'green'
* 'red'
* 'purple'
* 'brown'
* 'pink'
* 'gray'
* 'olive'
* 'cyan'
* Apart from above mentioned colors, the colors mentioned in
https://xkcd.com/color/rgb are also supported.
Default Value: blue
Types: str
title:
Optional Argument.
Specifies the title for the Axis.
Types: str
xlabel:
Optional Argument.
Specifies the label for x-axis.
Notes:
* When set to empty string, label is not displayed for x-axis.
* When set to None, name of the x-axis column is displayed as
label.
Types: str
xlim:
Optional Argument.
Specifies the range for xtick values.
Types: tuple
xtick_format:
Optional Argument.
Specifies whether to format tick values for x-axis or not.
Types: str
ylabel:
Optional Argument.
Specifies the label for y-axis.
Notes:
* When set to empty string, label is not displayed for y-axis.
* When set to None, name of the y-axis column(s) is displayed as
label.
Types: str
ylim:
Optional Argument.
Specifies the range for ytick values.
Types: tuple
ytick_format:
Optional Argument.
Specifies whether to format tick values for y-axis or not.
Types: str
vmin:
Optional Argument.
Specifies the lower range of the color map. By default, the range
is derived from data and color codes are assigned accordingly.
Note:
"vmin" significant only for Geometry Plot.
Types: int OR float
vmax:
Optional Argument.
Specifies the upper range of the color map. By default, the range is
derived from data and color codes are assigned accordingly.
Note:
"vmax" Significant only for Geometry Plot.
For example:
Assuming user wants to use colormap 'matter' and derive the colors for
values which are in between 1 and 100.
Note:
Colormap 'matter' starts with Pale Yellow and ends with Violet.
* If "colormap_range" is not specified, then range is derived from
existing values. Thus, colors are represented as below in the whole range:
* 1 as Pale Yellow.
* 100 as Violet.
* If "colormap_range" is specified as -100 and 100, the value 1 is at middle of
the specified range. Thus, colors are represented as below in the whole range:
* -100 as Pale Yellow.
* 1 as Orange.
* 100 as Violet.
Types: int OR float
wiggle_fill:
Optional Argument.
Specifies whether to fill the wiggle area or not. By default, the right
positive half of the wiggle is not filled. If specified as True, wiggle
area is filled.
Note:
Applicable only for the wiggle plot.
Default Value: False
Types: bool
wiggle_scale:
Optional Argument.
Specifies the scale of the wiggle. By default, the amplitude of wiggle is scaled
relative to RMS of the first payload. In certain cases, it can lead to excessively
large wiggles. Use "wiggle_scale" to adjust the relative size of the wiggle.
Note:
Applicable only for the wiggle and mesh plots.
Types: int OR float
ignore_nulls:
Optional Argument.
Specifies whether to delete rows with null values or not present in 'x', 'y' and
'scale' params.
Default Value: False
Types: bool
RAISES:
TeradataMlException
EXAMPLES:
# Load example data.
>>> load_example_data("movavg", "ibm_stock")
>>> load_example_data("uaf", ["waveletTable", "us_air_pass"])
>>> load_example_data("teradataml", "iris_input")
# Create teradataml DataFrame objects.
>>> ibm_stock = DataFrame("ibm_stock")
>>> mesh = DataFrame("waveletTable")
>>> us_air_pass = DataFrame("us_air_pass")
>>> iris_input = DataFrame("iris_input")
# Example 1: Line Plot - This example creates simple line plot
# and composite line plot with 2 columns in y-axis.
# Print the DataFrame.
>>> print(ibm_stock)
name period stockprice
id
244 ibm 62/05/04 475.0
101 ibm 61/10/10 557.0
284 ibm 62/07/02 350.0
141 ibm 61/12/07 577.0
120 ibm 61/11/06 592.0
303 ibm 62/07/30 376.0
263 ibm 62/06/01 364.0
305 ibm 62/08/01 385.0
122 ibm 61/11/08 596.0
265 ibm 62/06/05 370.0
# Simple Line Plot.
>>> plot = ibm_stock.plot(x=ibm_stock.period, y=ibm_stock.stockprice,
title="period vs stockprice",
heading="Simple Line Plot")
# Display the plot.
>>> plot.show()

# Composite Line Plot.
>>> figure = Figure(width=800, height=900, image_type="jpg",
heading="Composite Line Plot")
# Print the DataFrame.
>>> print(ibm_stock)
name period stockprice
id
244 ibm 62/05/04 475.0
101 ibm 61/10/10 557.0
284 ibm 62/07/02 350.0
141 ibm 61/12/07 577.0
120 ibm 61/11/06 592.0
303 ibm 62/07/30 376.0
263 ibm 62/06/01 364.0
305 ibm 62/08/01 385.0
122 ibm 61/11/08 596.0
265 ibm 62/06/05 370.0
>>> n1 = ibm_stock.assign(n=ibm_stock.stockprice * 2)
>>> plot = n1.plot(x=n1.period, y=[n1.stockprice, n1.n],
color=['dark orange', 'sand'], figure=figure)
# Display the plot.
>>> plot.show()

# Example 2: Bar Plot - This example creates simple bar plot
# and composite bar plot with 2 columns in y-axis.
# Print the DataFrame.
>>> print(ibm_stock)
name period stockprice
id
244 ibm 62/05/04 475.0
101 ibm 61/10/10 557.0
284 ibm 62/07/02 350.0
141 ibm 61/12/07 577.0
120 ibm 61/11/06 592.0
303 ibm 62/07/30 376.0
263 ibm 62/06/01 364.0
305 ibm 62/08/01 385.0
122 ibm 61/11/08 596.0
265 ibm 62/06/05 370.0
# Simple Bar Plot.
>>> plot = ibm_stock.plot(x=ibm_stock.period, y=ibm_stock.stockprice,
kind='bar', xtick_format='MMM', ytick_format='9,99.99',
xlabel='xlabel', ylabel='ylabel', color="orange")
# Display the plot.
>>> plot.show()

# Composite Bar Plot.
# Import Figure.
>>> from teradataml import Figure
>>> figure = Figure(width=800, height=900, image_type="jpg", heading="Heading")
# Print the DataFrame.
>>> print(us_air_pass)
TD_TIMECODE id idx international domestic
0 17/11/01 0 10 7.72 61.91
1 18/01/01 0 12 8.60 55.83
2 18/02/01 0 13 7.64 54.08
3 17/01/01 0 0 8.51 54.11
4 17/03/01 0 2 9.00 63.96
5 17/04/01 0 3 9.16 61.10
6 17/05/01 0 4 9.24 64.44
7 17/06/01 0 5 10.26 66.75
8 17/02/01 0 1 7.30 51.08
9 17/12/01 0 11 8.96 61.37
>>> plot = us_air_pass.plot(x=us_air_pass.idx, y=[us_air_pass.international, us_air_pass.domestic],
kind='bar', color=['blue', 'red'], figure=figure,
heading="Composite Bar Plot", figsize=(1200, 1100))
# Display the plot.
>>> plot.show()

# Example 3: Scatter Plot - This example creates simple scatter plot
# and composite scatter plot with 2 columns in y-axis.
# Print the DataFrame.
>>> print(iris_input)
sepal_length sepal_width petal_length petal_width species
id
141 6.7 3.1 5.6 2.4 3
99 5.1 2.5 3.0 1.1 2
17 5.4 3.9 1.3 0.4 1
139 6.0 3.0 4.8 1.8 3
15 5.8 4.0 1.2 0.2 1
137 6.3 3.4 5.6 2.4 3
118 7.7 3.8 6.7 2.2 3
120 6.0 2.2 5.0 1.5 3
101 6.3 3.3 6.0 2.5 3
122 5.6 2.8 4.9 2.0 3
# Simple Scatter Plot.
>>> plot = plot = iris_input.plot(x=iris_input.sepal_length, y=iris_input.petal_length,
kind='scatter', xlabel='sepal_length',
ylabel='petal_length',
color="red", grid_color='black',
grid_linewidth=1, grid_linestyle="-",
marker="p", marker_size=1,
title="Scatter plot of sepal_length vs petal_length")
# Display the plot.
>>> plot.show()

# Composite Scatter Plot.
# Create DataFrame objects for species 1, 2, 3.
>>> iris_sp1 = iris_input[iris_input.species == 1]
>>> iris_sp2 = iris_input[iris_input.species == 2]
>>> iris_sp3 = iris_input[iris_input.species == 3]
# Print the DataFrames.
>>> print(iris_sp1)
sepal_length sepal_width petal_length petal_width species
id
38 4.9 3.6 1.4 0.1 1
7 4.6 3.4 1.4 0.3 1
26 5.0 3.0 1.6 0.2 1
17 5.4 3.9 1.3 0.4 1
34 5.5 4.2 1.4 0.2 1
13 4.8 3.0 1.4 0.1 1
32 5.4 3.4 1.5 0.4 1
11 5.4 3.7 1.5 0.2 1
15 5.8 4.0 1.2 0.2 1
36 5.0 3.2 1.2 0.2 1
>>> print(iris_sp2)
sepal_length sepal_width petal_length petal_width species
id
59 6.6 2.9 4.6 1.3 2
57 6.3 3.3 4.7 1.6 2
97 5.7 2.9 4.2 1.3 2
99 5.1 2.5 3.0 1.1 2
51 7.0 3.2 4.7 1.4 2
70 5.6 2.5 3.9 1.1 2
89 5.6 3.0 4.1 1.3 2
68 5.8 2.7 4.1 1.0 2
53 6.9 3.1 4.9 1.5 2
78 6.7 3.0 5.0 1.7 2
>>> print(iris_sp3)
sepal_length sepal_width petal_length petal_width species
id
133 6.4 2.8 5.6 2.2 3
131 7.4 2.8 6.1 1.9 3
110 7.2 3.6 6.1 2.5 3
122 5.6 2.8 4.9 2.0 3
141 6.7 3.1 5.6 2.4 3
120 6.0 2.2 5.0 1.5 3
139 6.0 3.0 4.8 1.8 3
118 7.7 3.8 6.7 2.2 3
101 6.3 3.3 6.0 2.5 3
112 6.4 2.7 5.3 1.9 3
# Import subplots.
>>> from teradataml import subplots
# Function to create a figure and a set of subplots.
# The function makes it convenient to create common layouts of subplots,
# including the enclosing figure object.
# This will help to create a figure with 3 subplots in 1 row.
# fig and axes is passed to plot().
>>> fig, axes = subplots(nrows=1, ncols=3)
>>> p = iris_sp1.plot(x=iris_sp1.sepal_length, y=iris_sp1.petal_length,
ax=axes[0], xlim=(0,10), ylim=(0,8),
figure=fig, kind="scatter",
title="Scatter plot of species 1: Sepal Length v/s Petal Length", color="blue", marker="*")
>>> p = iris_sp2.plot(x=iris_sp2.sepal_length, y=iris_sp2.petal_length,
ax=axes[1], xlim=(0,10), ylim=(0,8),
figure=fig, kind="scatter",
title="Scatter plot of species 2: Sepal Length v/s Petal Length", color="red", marker="p")
>>> p = iris_sp3.plot(x=iris_sp3.sepal_length, y=iris_sp3.petal_length,
ax=axes[2], xlim=(0,10), ylim=(0,8),
figure=fig, kind="scatter",
title="Scatter plot of species 3: Sepal Length v/s Petal Length", color="orange", marker="1")
# Display the plot.
>>> plot.show()

# Example 4: Mesh Plot - This example creates simple mesh plot.
# Print the DataFrame.
>>> print(mesh)
x t y c
ID
a 94.0 800.0 701.0 -2.034400e-22
a 94.0 800.0 702.0 -4.217551e-22
a 94.0 800.0 702.5 -5.192715e-22
a 94.0 800.0 703.0 -5.182389e-22
a 94.0 800.0 704.0 5.473949e-22
a 94.0 800.0 704.5 2.389177e-21
a 94.0 800.0 703.5 -2.592409e-22
a 94.0 800.0 701.5 -3.051780e-22
a 94.0 800.0 700.5 -1.266145e-22
a 94.0 800.0 700.0 -7.378603e-23
# Simple Mesh Plot.
>>> plot = mesh.plot(x=mesh.x, y=mesh.y, scale=mesh.c,
kind='mesh', cmap='ice', vmin=-0.5,
vmax=0.5)
# Display the plot.
>>> plot.show()

# Example 5: Wiggle Plot - This example creates simple wiggle plot.
# Simple Wiggle Plot.
# Create teradataml DataFrame object.
>>> wiggle = DataFrame("waveletTable")
# Print the DataFrame.
>>> print(wiggle)
x t y c
ID
a 94.0 800.0 701.0 -2.034400e-22
a 94.0 800.0 702.0 -4.217551e-22
a 94.0 800.0 702.5 -5.192715e-22
a 94.0 800.0 703.0 -5.182389e-22
a 94.0 800.0 704.0 5.473949e-22
a 94.0 800.0 704.5 2.389177e-21
a 94.0 800.0 703.5 -2.592409e-22
a 94.0 800.0 701.5 -3.051780e-22
a 94.0 800.0 700.5 -1.266145e-22
a 94.0 800.0 700.0 -7.378603e-23
>>> plot = wiggle.plot(x=wiggle.x, y=wiggle.y, scale=wiggle.c, kind='wiggle')
# Display the plot.
>>> plot.show()

# Examples for subplot.
# Example 1: This example creates a figure with subplot with scatter plots.
# Load example data.
>>> load_example_data("uaf", "house_values")
# Create teradataml DataFrame objects.
>>> house_values = DataFrame("house_values")
# Print the DataFrame.
>>> print(house_values)
TD_TIMECODE house_val salary mortgage
cityid
33 2020-07-01 08:00:00.000000 66000.0 29000.0 0.039
33 2020-04-01 08:00:00.000000 80000.0 22000.0 0.029
33 2020-05-01 08:00:00.000000 184000.0 49000.0 0.030
33 2020-06-01 08:00:00.000000 320000.0 112000.0 0.017
33 2020-09-01 08:00:00.000000 195000.0 72000.0 0.049
33 2020-10-01 08:00:00.000000 134000.0 89000.0 0.045
33 2020-11-01 08:00:00.000000 198000.0 49000.0 0.052
33 2020-08-01 08:00:00.000000 144000.0 74000.0 0.034
33 2020-03-01 08:00:00.000000 220000.0 76000.0 0.035
33 2020-02-01 08:00:00.000000 144000.0 50000.0 0.040
# Import subplots.
>>> from teradataml import subplots
# This will help to create a figure with 2 subplots in 1 row.
# fig and axes is passed to plot().
>>> fig, axes = subplots(nrows=1, ncols=2)
# Create plot with house_val, salary and salary and mortgage.
>>> plot = house_values.plot(x=house_values.house_val, y=house_values.salary,
ax=axes[0], figure=fig, kind="scatter",
xlim=(100000,250000), ylim=(25000, 100000),
title="Scatter plot of House Val v/s Salary",
color="green")
>>> plot = house_values.plot(x=house_values.salary, y=house_values.mortgage,
ax=axes[1], figure=fig, kind="scatter",
title="Scatter plot of House Val v/s Mortgage",
color="red")
# Show the plot.
>>> plot.show()

Example 2:
# Subplot with grid. This will generate a figure with 2 subplots in first row
# first column and second column respectively and 1 subplot in second row.
>>> fig, axes = subplots(grid = {(1, 1): (1, 1), (1, 2): (1, 1),
(2, 1): (1, 2)})
# Print the DataFrame.
>>> print(house_values)
TD_TIMECODE house_val salary mortgage
cityid
33 2020-07-01 08:00:00.000000 66000.0 29000.0 0.039
33 2020-04-01 08:00:00.000000 80000.0 22000.0 0.029
33 2020-05-01 08:00:00.000000 184000.0 49000.0 0.030
33 2020-06-01 08:00:00.000000 320000.0 112000.0 0.017
33 2020-09-01 08:00:00.000000 195000.0 72000.0 0.049
33 2020-10-01 08:00:00.000000 134000.0 89000.0 0.045
33 2020-11-01 08:00:00.000000 198000.0 49000.0 0.052
33 2020-08-01 08:00:00.000000 144000.0 74000.0 0.034
33 2020-03-01 08:00:00.000000 220000.0 76000.0 0.035
33 2020-02-01 08:00:00.000000 144000.0 50000.0 0.040
# Create plot with house_val, salary and salary and mortgage.
>>> plot = house_values.plot(x=house_values.house_val, y=house_values.salary,
ax=axes[0], figure=fig, kind="scatter",
title="Scatter plot of House Val v/s Salary",
color="green")
>>> plot = house_values.plot(x=house_values.salary, y=house_values.mortgage,
ax=axes[1], figure=fig, kind="scatter",
title="Scatter plot of Salary v/s Mortgage",
color="red")
>>> plot = house_values.plot(x=house_values.salary, y=house_values.mortgage,
ax=axes[2], figure=fig, kind="scatter",
title="Scatter plot of House Val v/s Mortgage",
color="blue")
# Show the plot.
>>> plot.show()
