I'm walking through basic tutorials for matplotlib, and the example code that I'm working on is:
import numpy as np
import matplotlib.pylab as plt
x=[1,2,3,4]
y=[5,6,7,8]
line, = plt.plot(x,y,'-')
plt.show()
Does anyone know what the comma after line (line,=plt.plot(x,y,'-')
) means?
I thought it was a typo but obviously the whole code doesn't work if I omit the comma.
Matplotlib plot a line in 3D Matplotlib is the widely used data visualization library in Python. It provides a variety of plots and data visualization tools to create 2D plots from the data in lists or arrays in python. Matplotlib is a cross-platform library built on NumPy arrays.
# Importing packages import matplotlib.pyplot as plt # Define x and y values x = y = # Plot a simple line chart without any feature plt.plot (x, y) plt.show ()
Matplotlib plot line color You can change the line color in a line chart in python using matplotlib. You need to specify the parameter color in the plot () function of matplotlib. There are several colors available in python.
Matplotlib plot vertical line at date You can add dates as ticklabels and can plot vertical lines at a date in matplotlib python. You need to import the datetimes function from datetime module in python for creating the date-formatted values. You need mdates sub-module from the matplotlib.dates to format the dates for the plot.
plt.plot
returns a list of the Line2D
objects plotted, even if you plot only one line.
That comma is unpacking the single value into line
.
ex
a, b = [1, 2]
a, = [1, ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With