from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
import warnings
warnings.filterwarnings("ignore")
np.set_printoptions(suppress=True) # 设置numpy不以科学计数法保存和显示
# pandas 可视化
for riqi in data_zc['日期'].unique():
for checi in data_zc[data_zc['日期'] == riqi]['车次'].unique():
dff1 = data_zc[(data_zc['日期'] == riqi) & (data_zc['车次'] == checi)]
dff1.iloc[:, 3:-1].plot(kind='line', subplots=True, layout=(1, 5), sharex=False, sharey=False, fontsize=8, figsize=(16,3))
plt.suptitle(f'{riqi} 第 {checi} 车正常', fontsize = 20)
plt.show();
df2.iloc[:, 1:-1].plot(kind='line', subplots=True, layout=(1, 5), sharex=False, sharey=False, fontsize=8, figsize=(16,3));
plt.suptitle(sname, x=0.5, y=0.96, fontsize=18, color='k')
# 设置子图间距
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5)
# 预设风格
from matplotlib.pylab import style #自定义图表风格
style.use('ggplot')
plt.xticks(new_data.index[::], rotation=40, horizontalalignment='right', fontsize=10) # x轴刻度
from bokeh.layouts import column
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
from bokeh.transform import jitter
xs = sorted(cf.编号.unique())
# p1 = figure(width=1500, height=500, title="Years vs mpg without jittering")
# p1.xgrid.grid_line_color = None
# p1.xaxis.ticker = xs
# p1.scatter(x='编号', y='数据', size=2, alpha=0.4, source=cf)
p2 = figure(width=1500, height=500, title="Years vs mpg with jittering")
p2.xgrid.grid_line_color = None
p2.xaxis.ticker = xs
p2.scatter(x=jitter('编号', 0.8), y='数据', size=2, alpha=0.4, source=cf)
show(p2)
# show(column(p1, p2))
from bokeh.layouts import column
from bokeh.plotting import figure, show
from bokeh.sampledata.autompg import autompg
from bokeh.transform import jitter
autompg
years = sorted(autompg.yr.unique())
p1 = figure(width=600, height=300, title="Years vs mpg without jittering")
p1.xgrid.grid_line_color = None
p1.xaxis.ticker = years
p1.scatter(x='yr', y='displ', size=2, alpha=0.4, source=autompg)
p2 = figure(width=600, height=300, title="Years vs mpg with jittering")
p2.xgrid.grid_line_color = None
p2.xaxis.ticker = years
p2.scatter(x=jitter('yr', 0.4), y='displ', size=3, alpha=0.4, source=autompg)
show(column(p1, p2))
# 热力图绘制
import seaborn as sns
corr = data1.corr()
mask = np.zeros_like(corr)
mask[np.triu_indices_from(mask)] = True
plt.figure(figsize=(6, 6))
with sns.axes_style("white"):
ax = sns.heatmap(corr, annot=True, mask=mask, square=True, cmap="YlGnBu")
plt.show();
# 矩阵散点图绘制
sns.pairplot(data1, height=2)
sns.pairplot(data1,kind="reg",diag_kind="kde", height=2);
Python 绘图
最新推荐文章于 2022-03-25 19:09:03 发布