为了账号安全,请及时绑定邮箱和手机立即绑定

坐标轴不显示在 Matplotlib 中

坐标轴不显示在 Matplotlib 中

catspeake 2023-03-16 17:48:10
import matplotlib.pyplot as pltimport pandas as pdimport pylab as plimport numpy as np%matplotlib inline!wget -O FuelConsumption.csv https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses- data/CognitiveClass/ML0101ENv3/labs/FuelConsumptionCo2.csvdf = pd.read_csv("FuelConsumption.csv")df.head()df1 = df[['ENGINESIZE','CYLINDERS','FUELCONSUMPTION_COMB','CO2EMISSIONS']]df1.head(9)plt.scatter(df1.ENGINESIZE , df1.CO2EMISSIONS , color = "black")plt.xlabel=("enginesize")plt.ylabel=("emission")plt.show()当我尝试运行这段代码时,我得到了没有轴标签的散点图。如果有人可以帮助我,我该如何获得轴标签?
查看完整描述

1 回答

?
交互式爱情

TA贡献1712条经验 获得超3个赞

您需要将标签名称传递给xlabel和ylabel。如果它抛出错误 -TypeError: 'str' object is not callable然后重新启动 ipython 内核


import matplotlib.pyplot as plt

import pandas as pd

import pylab as pl

import numpy as np

%matplotlib inline


df = pd.read_csv("FuelConsumption.csv")

df.head()


df1 = df[['ENGINESIZE','CYLINDERS','FUELCONSUMPTION_COMB','CO2EMISSIONS']]

df1.head(9)


plt.scatter(df1.ENGINESIZE , df1.CO2EMISSIONS , color = "black")

plt.xlabel("enginesize")

plt.ylabel("emission")

plt.show()

//img1.sycdn.imooc.com//6412e6010001104806560445.jpg

查看完整回答
反对 回复 2023-03-16
  • 1 回答
  • 0 关注
  • 159 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信