要想查阅有关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))
结果如下:
如果觉得不错,就点赞或者关注或者留言~~
谢谢~ ~