Python3 - 数据可视化练习题(含答案): plt.legend(), plot.hist().....

要想查阅有关style sheets, 请点击这里查阅

先展示所要使用的dataset:

import pandas as pd
import matplotlib.pyplot as plt
df3 = pd.read_csv('df3')
df3.info()
df3.head()

结果如下:
在这里插入图片描述
使用scatter():

# s: size
df3.plot.scatter(x='a',y='b',figsize=(12,5),s=50)

df3.plot.scatter(x='a',y='b',figsize=(12,5))

结果如下:
在这里插入图片描述
使用hist():

# Create a histogram of the 'a' column
df3['a'].hist()

df3['a'].plot.hist(bins=10,color='red',alpha=0.4)

结果如下:
在这里插入图片描述

使用style sheets:

# Use style sheets to set the style to 'ggplot' and redo the histogram from above graph. Also figure out how to add more bins to it
# ggplot: emulates the aesthetics of ggplot (a popular plotting package for R).
plt.style.use('ggplot')
df3['a'].plot.hist(bins=20,alpha=0.4)

结果如下:
在这里插入图片描述
使用plot.box():

# Create a boxplot comparing the a and b columns
df3[['a','b']].plot.box()

结果如下:
在这里插入图片描述
使用plot.kde():

# Create a kde plot of the 'd' column
df3['d'].plot.kde()

结果如下:
在这里插入图片描述
kde() 和 density() 一样:

# Figure out how to increase the linewidth and make the linestyle dashed.
df3['d'].plot.kde(lw=5,ls='--')

# Figure out how to increase the linewidth and make the linestyle dashed.
df3['d'].plot.density(lw=5,ls='--')

结果如下:
在这里插入图片描述
使用plt.legend() 将标注框进行变换位置:

# 如何把lengend 移出图形外部?
df3['d'].plot.density(lw=5,ls='--')
# center right: 是以标注的中间右边框为标准点
plt.legend(loc='center right', bbox_to_anchor=(1,0.5))

# 如何把lengend 移出图形外部?
df3['d'].plot.density(lw=5,ls='--')
# center left: 是以标注的中间左边框为标准点
plt.legend(loc='center left', bbox_to_anchor=(1,0.5))

df3['d'].plot.density(lw=5,ls='--')
plt.legend(loc=(1.1,0))

结果如下:
在这里插入图片描述
在这里插入图片描述
如果觉得不错,就点赞或者关注或者留言~~
谢谢~ ~

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值