plot(matplotlib.pyplot)绘图(散点图)

使用数据地址:链接:https://pan.baidu.com/s/1wXtZRDcM-JKk_dIDRyd_dg?pwd=pyth
提取码:pyth
(电影评分数据)
取两列数据绘制散点图,需使用scatter函数

import pandas as pd
reviews = pd.read_csv('fandango_scores.csv')
cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']#取一些列做新的数据
norm_reviews = reviews[cols]
print(norm_reviews[0:2])
'''
     FILM  RT_user_norm  Metacritic_user_nom  \
0  Avengers: Age of Ultron (2015)           4.3                 3.55   
1               Cinderella (2015)           4.0                 3.75   

   IMDB_norm  Fandango_Ratingvalue  Fandango_Stars  
0       3.90                   4.5             5.0  
1       3.55                   4.5             5.0  
'''
#Let's look at a plot that can help us visualize many points.
fig, ax = plt.subplots()
ax.scatter(norm_reviews['Fandango_Ratingvalue'], norm_reviews['RT_user_norm'])#使用scatter函数
ax.set_xlabel('Fandango')
ax.set_ylabel('Rotten Tomatoes')
plt.show()

在这里插入图片描述

交换下坐标轴数据

#Switching Axes
fig = plt.figure(figsize=(5,10))
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
ax1.scatter(norm_reviews['Fandango_Ratingvalue'], norm_reviews['RT_user_norm'])
ax1.set_xlabel('Fandango')
ax1.set_ylabel('Rotten Tomatoes')
ax2.scatter(norm_reviews['RT_user_norm'], norm_reviews['Fandango_Ratingvalue'])
ax2.set_xlabel('Rotten Tomatoes')
ax2.set_ylabel('Fandango')
plt.show()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
matplotlib.pyplot是一个Python中的绘图工具,可以用于绘制各种类型的图形,包括线图、散点图、条形图、饼图等等。下面介绍一些matplotlib.pyplot绘图显示控制的方法。 1. 设置图像大小 可以使用`plt.figure(figsize=(x, y))`来设置图像的大小,其中x和y分别表示宽度和高度。例如,`plt.figure(figsize=(8, 6))`表示设置图像宽度为8,高度为6。 2. 设置坐标轴范围 可以使用`plt.xlim(xmin, xmax)`和`plt.ylim(ymin, ymax)`来设置x轴和y轴的范围。例如,`plt.xlim(0, 10)`表示设置x轴范围为0到10。 3. 设置坐标轴标签 可以使用`plt.xlabel(xlabel)`和`plt.ylabel(ylabel)`来设置x轴和y轴的标签。例如,`plt.xlabel("x轴")`表示设置x轴标签为“x轴”。 4. 设置图像标题 可以使用`plt.title(title)`来设置图像的标题。例如,`plt.title("图像标题")`表示设置图像的标题为“图像标题”。 5. 设置图例 可以使用`plt.legend()`来显示图例。在绘制图像时,需要在`plot()`函数中传入`label`参数,表示该曲线的标签。例如: ```python import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y1 = [1, 2, 3, 4, 5] y2 = [1, 4, 9, 16, 25] plt.plot(x, y1, label="y1") plt.plot(x, y2, label="y2") plt.legend() plt.show() ``` 在上面的例子中,`plt.plot(x, y1, label="y1")`表示绘制一条曲线,标签为“y1”。 6. 设置曲线颜色和线型 可以使用`plt.plot(x, y, color, linestyle)`来设置曲线的颜色和线型。其中,`color`参数表示颜色,可以是字符串(如“r”表示红色)或RGB值(如(1,0,0)表示红色);`linestyle`参数表示线型,可以是字符串(如“-”表示实线)或符号(如“-.”表示点划线)。例如: ```python import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [1, 4, 9, 16, 25] plt.plot(x, y, color="r", linestyle="-.") plt.show() ``` 在上面的例子中,`plt.plot(x, y, color="r", linestyle="-.")`表示绘制一条红色的点划线。 以上就是一些常用的matplotlib.pyplot绘图显示控制方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值