如何用matplotlib或seaborn将多个图形绘制成一个图形

lf5gs5x2  于 2023-01-21  发布在  其他
关注(0)|答案(2)|浏览(225)

这是我的 Dataframe 看起来像:单击行以下载 Dataframe
enter link description here for dataframe

我已经尝试了以下代码:

plt.plot(LessDF['DeptAvg'] == 'COA111', LessDF['week1'])
plt.plot(LessDF['DeptAvg'] == 'COA111', LessDF['week2'])
plt.plot(LessDF['DeptAvg'] == 'COA111', LessDF['week3'])

我的代码有输出:

我希望输出如下:

我怎样才能用matplotlib或seaborn得到这个输出?

bq8i3lrv

bq8i3lrv1#

对于所应用的筛选器,DeptAvg列中的所有值都是67。
此外,您还提供了一个布尔值作为x:LessDF['DeptAvg'] == 'COA111'.
此外,您将条件应用于错误的列DeptAvg,而不是classes

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('../../../Desktop/LessDF.csv')
df_filtered = df[df['classes'] == 'COA111' ]

plt.plot(df_filtered['week1'],df_filtered['DeptAvg'],alpha=.5,)
plt.plot(df_filtered['week2'],df_filtered['DeptAvg'],alpha=.5)
plt.plot(df_filtered['week3'],df_filtered['DeptAvg'],alpha=.5)

plt.legend(['week1','week2','week3'])

plt.show()

更多信息here

50few1ms

50few1ms2#

# I done this using seaborn you can use matplotlib in between to code
plt.figure(figsize=(16, 16)) 
plt.subplot(no_of_rows, no_of_columns, plot_num)
plt.title('Any title 1')
sns.boxplot(df['column_name'])

Example :- we want 2 rows with columns of plots then we use
plt.subplot(2, 2, 1)
plt.title('Any title 1')
sns.distplot(df['column_name'], bins=20)

plt.subplot(2, 2, 2)
plt.title('Any title 2')
sns.distplot(df['column_name'], bins=20)

plt.subplot(2, 2, 3)
plt.title('Any title 3')
sns.distplot(df['column_name'], bins=20)

plt.subplot(2, 2, 4)
plt.title('Any title 4')
sns.distplot(df['column_name'], bins=20)

plt.show()

相关问题