GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Installation
  • Documentation
  • Examples
  • Tutorials
  • Contributing

This view

  • Original page
  • New address

GeezerVison is showing matplotlib.org — matplotlib.axes.Axes.plot — Matplotlib 3.1.2 documentation

You are reading an old version of the documentation (v3.1.1). For the latest version see https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html
Version 3.1.2
matplotlib
Fork me on GitHub

Navigation

  • index
  • modules |
  • next |
  • previous |
  • home| 
  • contents »
  • API Overview »
  • matplotlib.axes »

Quick search

Table of Contents

  • matplotlib.axes.Axes.plot
    • Examples using matplotlib.axes.Axes.plot

Related Topics

  • Documentation overview
    • API Overview
      • matplotlib.axes
        • Previous: matplotlib.axes.subplot_class_factory
        • Next: matplotlib.axes.Axes.errorbar
Show Page Source

matplotlib.axes.Axes.plot¶

Axes.plot(self, *args, scalex=True, scaley=True, data=None, **kwargs)[source]¶

Plot y versus x as lines and/or markers.

Call signatures:

plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)

The coordinates of the points or line nodes are given by x, y.

The optional parameter fmt is a convenient way for defining basic formatting like color, marker and linestyle. It's a shortcut string notation described in the Notes section below.

>>> plot(x, y)        # plot x and y using default line style and color
>>> plot(x, y, 'bo')  # plot x and y using blue circle markers
>>> plot(y)           # plot y using x as index array 0..N-1
>>> plot(y, 'r+')     # ditto, but with red plusses

You can use Line2D properties as keyword arguments for more control on the appearance. Line properties and fmt can be mixed. The following two calls yield identical results:

>>> plot(x, y, 'go--', linewidth=2, markersize=12)
>>> plot(x, y, color='green', marker='o', linestyle='dashed',
...      linewidth=2, markersize=12)

When conflicting with fmt, keyword arguments take precedence.

Plotting labelled data

There's a convenient way for plotting objects with labelled data (i.e. data that can be accessed by index obj['y']). Instead of giving the data in x and y, you can provide the object in the data parameter and just give the labels for x and y:

>>> plot('xlabel', 'ylabel', data=obj)

All indexable objects are supported. This could e.g. be a dict, a pandas.DataFame or a structured numpy array.

Plotting multiple sets of data

There are various ways to plot multiple sets of data.

  • The most straight forward way is just to call plot multiple times. Example:

    >>> plot(x1, y1, 'bo')
    >>> plot(x2, y2, 'go')
    
  • Alternatively, if your data is already a 2d array, you can pass it directly to x, y. A separate data set will be drawn for every column.

    Example: an array a where the first column represents the x values and the other columns are the y columns:

    >>> plot(a[0], a[1:])
    
  • The third way is to specify multiple sets of [x], y, [fmt] groups:

    >>> plot(x1, y1, 'g^', x2, y2, 'g-')
    

    In this case, any additional keyword argument applies to all datasets. Also this syntax cannot be combined with the data parameter.

By default, each line is assigned a different style specified by a 'style cycle'. The fmt and line property parameters are only necessary if you want explicit deviations from these defaults. Alternatively, you can also change the style cycle using the 'axes.prop_cycle' rcParam.

Parameters:
x, y : array-like or scalar

The horizontal / vertical coordinates of the data points. x values are optional and default to range(len(y)).

Commonly, these parameters are 1D arrays.

They can also be scalars, or two-dimensional (in that case, the columns represent separate data sets).

These arguments cannot be passed as keywords.

fmt : str, optional

A format string, e.g. 'ro' for red circles. See the Notes section for a full description of the format strings.

Format strings are just an abbreviation for quickly setting basic line properties. All of these and more can also be controlled by keyword arguments.

This argument cannot be passed as keyword.

data : indexable object, optional

An object with labelled data. If given, provide the label names to plot in x and y.

Note

Technically there's a slight ambiguity in calls where the second label is a valid fmt. plot('n', 'o', data=obj) could be plt(x, y) or plt(y, fmt). In such cases, the former interpretation is chosen, but a warning is issued. You may suppress the warning by adding an empty format string plot('n', 'o', '', data=obj).

Returns:
lines

A list of Line2D objects representing the plotted data.

Other Parameters:
scalex, scaley : bool, optional, default: True

These parameters determined if the view limits are adapted to the data limits. The values are passed on to autoscale_view.

**kwargs : Line2D properties, optional

kwargs are used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color. Example:

>>> plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)
>>> plot([1,2,3], [1,4,9], 'rs',  label='line 2')

If you make multiple lines with one plot command, the kwargs apply to all those lines.

Here is a list of available Line2D properties:

Property Description
agg_filter a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
alpha float
animated bool
antialiased or aa bool
clip_box Bbox
clip_on bool
clip_path [(Path, Transform) | Patch | None]
color or c color
contains callable
dash_capstyle {'butt', 'round', 'projecting'}
dash_joinstyle {'miter', 'round', 'bevel'}
dashes sequence of floats (on/off ink in points) or (None, None)
drawstyle or ds {'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'
figure Figure
fillstyle {'full', 'left', 'right', 'bottom', 'top', 'none'}
gid str
in_layout bool
label object
linestyle or ls {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
linewidth or lw float
marker marker style
markeredgecolor or mec color
markeredgewidth or mew float
markerfacecolor or mfc color
markerfacecoloralt or mfcalt color
markersize or ms float
markevery None or int or (int, int) or slice or List[int] or float or (float, float)
path_effects AbstractPathEffect
picker float or callable[[Artist, Event], Tuple[bool, dict]]
pickradius float
rasterized bool or None
sketch_params (scale: float, length: float, randomness: float)
snap bool or None
solid_capstyle {'butt', 'round', 'projecting'}
solid_joinstyle {'miter', 'round', 'bevel'}
transform matplotlib.transforms.Transform
url str
visible bool
xdata 1D array
ydata 1D array
zorder float

See also

scatter
XY scatter plot with markers of varying size and/or color ( sometimes also called bubble chart).

Notes

Format Strings

A format string consists of a part for color, marker and line:

fmt = '[marker][line][color]'

Each of them is optional. If not provided, the value from the style cycle is used. Exception: If line is given, but no marker, the data will be a line without markers.

Other combinations such as [color][marker][line] are also supported, but note that their parsing may be ambiguous.

Markers

character description
'.' point marker
',' pixel marker
'o' circle marker
'v' triangle_down marker
'^' triangle_up marker
'<' triangle_left marker
'>' triangle_right marker
'1' tri_down marker
'2' tri_up marker
'3' tri_left marker
'4' tri_right marker
's' square marker
'p' pentagon marker
'*' star marker
'h' hexagon1 marker
'H' hexagon2 marker
'+' plus marker
'x' x marker
'D' diamond marker
'd' thin_diamond marker
'|' vline marker
'_' hline marker

Line Styles

character description
'-' solid line style
'--' dashed line style
'-.' dash-dot line style
':' dotted line style

Example format strings:

'b'    # blue markers with default shape
'or'   # red circles
'-g'   # green solid line
'--'   # dashed line with default color
'^k:'  # black triangle_up markers connected by a dotted line

Colors

The supported color abbreviations are the single letter codes

character color
'b' blue
'g' green
'r' red
'c' cyan
'm' magenta
'y' yellow
'k' black
'w' white

and the 'CN' colors that index into the default property cycle.

If the color is the only part of the format string, you can additionally use any matplotlib.colors spec, e.g. full names ('green') or hex strings ('#008000').

Examples using matplotlib.axes.Axes.plot¶

../../_images/sphx_glr_categorical_variables_thumb.png

Plotting categorical variables

../../_images/sphx_glr_csd_demo_thumb.png

CSD Demo

../../_images/sphx_glr_eventcollection_demo_thumb.png

EventCollection Demo

../../_images/sphx_glr_fill_between_demo_thumb.png

Filling the area between lines

../../_images/sphx_glr_fill_betweenx_demo_thumb.png

Fill Betweenx Demo

../../_images/sphx_glr_joinstyle_thumb.png

Join styles and cap styles

../../_images/sphx_glr_line_demo_dash_control_thumb.png

Customizing dashed line styles

../../_images/sphx_glr_marker_fillstyle_reference_thumb.png

Marker filling-styles

../../_images/sphx_glr_marker_reference_thumb.png

Marker Reference

../../_images/sphx_glr_markevery_prop_cycle_thumb.png

prop_cycle property markevery in rcParams

../../_images/sphx_glr_psd_demo_thumb.png

Psd Demo

../../_images/sphx_glr_simple_plot_thumb.png

Simple Plot

../../_images/sphx_glr_span_regions_thumb.png

Using span_where

../../_images/sphx_glr_vline_hline_demo_thumb.png

hlines and vlines

../../_images/sphx_glr_contour_corner_mask_thumb.png

Contour Corner Mask

../../_images/sphx_glr_image_demo_thumb.png

Image Demo

../../_images/sphx_glr_irregulardatagrid_thumb.png

Contour plot of irregularly spaced data

../../_images/sphx_glr_plot_streamplot_thumb.png

Streamplot

../../_images/sphx_glr_specgram_demo_thumb.png

Spectrogram Demo

../../_images/sphx_glr_triinterp_demo_thumb.png

Triinterp Demo

../../_images/sphx_glr_watermark_image_thumb.png

Watermark image

../../_images/sphx_glr_align_labels_demo_thumb.png

Aligning Labels

../../_images/sphx_glr_axes_demo_thumb.png

Axes Demo

../../_images/sphx_glr_axes_margins_thumb.png

Zooming in and out using Axes.margins and the subject of "stickiness"

../../_images/sphx_glr_axes_props_thumb.png

Axes Props

../../_images/sphx_glr_broken_axis_thumb.png

Broken Axis

../../_images/sphx_glr_custom_figure_class_thumb.png

Custom Figure Class

../../_images/sphx_glr_demo_constrained_layout_thumb.png

Resizing axes with constrained layout

../../_images/sphx_glr_demo_tight_layout_thumb.png

Resizing axes with tight layout

../../_images/sphx_glr_fahrenheit_celsius_scales_thumb.png

Different scales on the same axes

../../_images/sphx_glr_invert_axes_thumb.png

Invert Axes

../../_images/sphx_glr_secondary_axis_thumb.png

Secondary Axis

../../_images/sphx_glr_subplot_demo_thumb.png

Basic Subplot Demo

../../_images/sphx_glr_subplots_demo_thumb.png

Creating multiple subplots using plt.subplots

../../_images/sphx_glr_two_scales_thumb.png

Plots with different scales

../../_images/sphx_glr_boxplot_demo_thumb.png

Boxplots

../../_images/sphx_glr_histogram_cumulative_thumb.png

Using histograms to plot a cumulative distribution

../../_images/sphx_glr_histogram_features_thumb.png

Demo of the histogram (hist) function with a few features

../../_images/sphx_glr_polar_demo_thumb.png

Polar Demo

../../_images/sphx_glr_polar_legend_thumb.png

Polar Legend

../../_images/sphx_glr_accented_text_thumb.png

Using accented text in matplotlib

../../_images/sphx_glr_annotation_demo_thumb.png

Annotating Plots

../../_images/sphx_glr_custom_legends_thumb.png

Composing Custom Legends

../../_images/sphx_glr_dashpointlabel_thumb.png

Dashpoint Label

../../_images/sphx_glr_date_thumb.png

Date tick labels

../../_images/sphx_glr_date_index_formatter_thumb.png

Custom tick formatter for time series

../../_images/sphx_glr_demo_annotation_box_thumb.png

Demo Annotation Box

../../_images/sphx_glr_engineering_formatter_thumb.png

Labeling ticks using engineering notation

../../_images/sphx_glr_legend_thumb.png

Legend using pre-defined labels

../../_images/sphx_glr_legend_demo_thumb.png

Legend Demo

../../_images/sphx_glr_mathtext_demo_thumb.png

Mathtext Demo

../../_images/sphx_glr_tex_demo_thumb.png

Rendering math equation using TeX

../../_images/sphx_glr_unicode_minus_thumb.png

Unicode minus

../../_images/sphx_glr_watermark_text_thumb.png

Text watermark

../../_images/sphx_glr_align_ylabels_thumb.png

Align y-labels

../../_images/sphx_glr_annotate_transform_thumb.png

Annotate Transform

../../_images/sphx_glr_annotation_basic_thumb.png

Annotating a plot

../../_images/sphx_glr_auto_subplots_adjust_thumb.png

Auto Subplots Adjust

../../_images/sphx_glr_dollar_ticks_thumb.png

Dollar Ticks

../../_images/sphx_glr_fig_axes_labels_simple_thumb.png

Simple axes labels

../../_images/sphx_glr_pyplot_formatstr_thumb.png

plot() format string

../../_images/sphx_glr_pyplot_three_thumb.png

Pyplot Three

../../_images/sphx_glr_text_commands_thumb.png

Text Commands

../../_images/sphx_glr_whats_new_98_4_fill_between_thumb.png

Fill Between

../../_images/sphx_glr_whats_new_99_spines_thumb.png

Whats New 0.99 Spines

../../_images/sphx_glr_color_demo_thumb.png

Color Demo

../../_images/sphx_glr_color_by_yvalue_thumb.png

Color by y-value

../../_images/sphx_glr_color_cycler_thumb.png

Styling with cycler

../../_images/sphx_glr_marker_path_thumb.png

Marker Path

../../_images/sphx_glr_path_patch_thumb.png

PathPatch object

../../_images/sphx_glr_quad_bezier_thumb.png

Bezier Curve

../../_images/sphx_glr_dark_background_thumb.png

Dark background style sheet

../../_images/sphx_glr_fivethirtyeight_thumb.png

FiveThirtyEight style sheet

../../_images/sphx_glr_ggplot_thumb.png

ggplot style sheet

../../_images/sphx_glr_anatomy_thumb.png

Anatomy of a figure

../../_images/sphx_glr_bachelors_degrees_by_gender_thumb.png

Bachelor's degrees by gender

../../_images/sphx_glr_integral_thumb.png

Integral as the area under a curve

../../_images/sphx_glr_xkcd_thumb.png

XKCD

../../_images/sphx_glr_animate_decay_thumb.png

Decay

../../_images/sphx_glr_bayes_update_thumb.png

The Bayes update

../../_images/sphx_glr_simple_anim_thumb.png

Animated line plot

../../_images/sphx_glr_unchained_thumb.png

MATPLOTLIB UNCHAINED

../../_images/sphx_glr_coords_demo_thumb.png

Coords demo

../../_images/sphx_glr_data_browser_thumb.png

Data Browser

../../_images/sphx_glr_keypress_demo_thumb.png

Keypress Demo

../../_images/sphx_glr_legend_picking_thumb.png

Legend Picking

../../_images/sphx_glr_looking_glass_thumb.png

Looking Glass

../../_images/sphx_glr_path_editor_thumb.png

Path Editor

../../_images/sphx_glr_pick_event_demo2_thumb.png

Pick Event Demo2

../../_images/sphx_glr_resample_thumb.png

Resampling Data

../../_images/sphx_glr_timers_thumb.png

Timers

../../_images/sphx_glr_histogram_thumb.png

Frontpage histogram example

../../_images/sphx_glr_membrane_thumb.png

Frontpage plot example

../../_images/sphx_glr_agg_buffer_to_array_thumb.png

Agg Buffer To Array

../../_images/sphx_glr_bbox_intersect_thumb.png

Changing colors of lines intersecting a box

../../_images/sphx_glr_demo_agg_filter_thumb.png

Demo Agg Filter

../../_images/sphx_glr_load_converter_thumb.png

Load converter

../../_images/sphx_glr_patheffect_demo_thumb.png

Patheffect Demo

../../_images/sphx_glr_pythonic_matplotlib_thumb.png

Pythonic Matplotlib

../../_images/sphx_glr_svg_filter_line_thumb.png

SVG Filter Line

../../_images/sphx_glr_common_date_problems_thumb.png

Fixing common date annoyances

../../_images/sphx_glr_create_subplots_thumb.png

Easily creating subplots

../../_images/sphx_glr_fill_between_alpha_thumb.png

Fill Between and Alpha

../../_images/sphx_glr_share_axis_lims_views_thumb.png

Sharing axis limits and views

../../_images/sphx_glr_aspect_loglog_thumb.png

Loglog Aspect

../../_images/sphx_glr_scales_thumb.png

Scales

../../_images/sphx_glr_centered_ticklabels_thumb.png

Centering labels between ticks

../../_images/sphx_glr_date_concise_formatter_thumb.png

Formatting date ticks using ConciseDateFormatter

../../_images/sphx_glr_date_index_formatter2_thumb.png

Date Index Formatter

../../_images/sphx_glr_major_minor_demo_thumb.png

Major and minor ticks

../../_images/sphx_glr_multiple_yaxis_with_spines_thumb.png

Multiple Yaxis With Spines

../../_images/sphx_glr_scalarformatter_thumb.png

Tick formatting using the ScalarFormatter

../../_images/sphx_glr_spine_placement_demo_thumb.png

Spine Placement Demo

../../_images/sphx_glr_spines_thumb.png

Spines

../../_images/sphx_glr_spines_bounds_thumb.png

Custom spine bounds

../../_images/sphx_glr_tick-locators_thumb.png

Tick locators

../../_images/sphx_glr_tick_label_right_thumb.png

Set default y-axis tick labels on the right

../../_images/sphx_glr_tick_labels_from_values_thumb.png

Setting tick labels from a list of values

../../_images/sphx_glr_tick_xlabel_top_thumb.png

Set default x-axis tick labels on the top

../../_images/sphx_glr_evans_test_thumb.png

Evans test

../../_images/sphx_glr_canvasagg_thumb.png

CanvasAgg demo

../../_images/sphx_glr_annotate_explain_thumb.png

Annotate Explain

../../_images/sphx_glr_connect_simple01_thumb.png

Connect Simple01

../../_images/sphx_glr_connectionstyle_demo_thumb.png

Connectionstyle Demo

../../_images/sphx_glr_demo_gridspec06_thumb.png

Nested GridSpecs

../../_images/sphx_glr_simple_annotate01_thumb.png

Simple Annotate01

../../_images/sphx_glr_simple_legend02_thumb.png

Simple Legend02

../../_images/sphx_glr_check_buttons_thumb.png

Check Buttons

../../_images/sphx_glr_cursor_thumb.png

Cursor

../../_images/sphx_glr_multicursor_thumb.png

Multicursor

../../_images/sphx_glr_radio_buttons_thumb.png

Radio Buttons

../../_images/sphx_glr_span_selector_thumb.png

Span Selector

../../_images/sphx_glr_usage_thumb.png

Usage Guide

../../_images/sphx_glr_artists_thumb.png

Artist tutorial

../../_images/sphx_glr_color_cycle_thumb.png

Styling with cycler

../../_images/sphx_glr_gridspec_thumb.png

Customizing Figure Layouts Using GridSpec and Other Functions

../../_images/sphx_glr_constrainedlayout_guide_thumb.png

Constrained Layout Guide

../../_images/sphx_glr_path_tutorial_thumb.png

Path Tutorial

../../_images/sphx_glr_transforms_tutorial_thumb.png

Transformations Tutorial

../../_images/sphx_glr_colors_thumb.png

Specifying Colors

../../_images/sphx_glr_text_intro_thumb.png

Text in Matplotlib Plots

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2018 The Matplotlib development team.
Last updated on Jan 05, 2020. Created using Sphinx 1.8.5. Doc version v3.1.1-79-g90d53b526.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.