matplotlib 2d线line,= plot逗号含义 [英] matplotlib 2d line line,=plot comma meaning

查看:485
本文介绍了matplotlib 2d线line,= plot逗号含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在逐步学习matplotlib的基础教程, 而我正在处理的示例代码是:

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()

有人知道行(line,=plt.plot(x,y,'-'))后的逗号是什么意思吗? 我以为这是一个错字,但如果省略逗号,显然整个代码将无法正常工作.

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.

推荐答案

plt.plot返回绘制的Line2D对象的列表,即使只绘制一条线.

plt.plot returns a list of the Line2D objects plotted, even if you plot only one line.

该逗号将单个值分解为line.

That comma is unpacking the single value into line.

ex

a, b = [1, 2]
a, = [1, ]

这篇关于matplotlib 2d线line,= plot逗号含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆