坐标轴不显示在 Matplotlib 中

import matplotlib.pyplot as plt

import pandas as pd

import pylab as pl

import numpy as np

%matplotlib inline


!wget -O FuelConsumption.csv https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses- 

data/CognitiveClass/ML0101ENv3/labs/FuelConsumptionCo2.csv


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

当我尝试运行这段代码时,我得到了没有轴标签的散点图。如果有人可以帮助我,我该如何获得轴标签?

http://img3.mukewang.com/6412e5f4000193d706510292.jpg

catspeake
浏览 160回答 1
1回答

交互式爱情

您需要将标签名称传递给xlabel和ylabel。如果它抛出错误 -TypeError: 'str' object is not callable然后重新启动 ipython 内核import matplotlib.pyplot as pltimport pandas as pdimport pylab as plimport numpy as np%matplotlib inlinedf = 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()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python