Python 尝试使用seaborn使用列名列表绘制图形
我试图通过使用列名列表打印一个seaborn绘图网格。它正在最后一个图上绘制所有内容Python 尝试使用seaborn使用列名列表绘制图形,python,seaborn,Python,Seaborn,我试图通过使用列名列表打印一个seaborn绘图网格。它正在最后一个图上绘制所有内容 fig, ax = plt.subplots(2,2, figsize=(10,10), sharex=True) for aa in listA: for j in range(2): for i in range(2): ax[i][j] = sns.lineplot(x='time', y=aa, data=new_df, color='r') 输出图
fig, ax = plt.subplots(2,2, figsize=(10,10), sharex=True)
for aa in listA:
for j in range(2):
for i in range(2):
ax[i][j] = sns.lineplot(x='time', y=aa, data=new_df, color='r')
输出图
尝试替换以下代码行:
ax[i][j] = sns.lineplot(x='time', y=aa, data=new_df, color='r')
以下是:
ax[i,j] = sns.lineplot(x='time', y=aa, data=new_df, color='r')
尝试替换以下代码行:
ax[i][j] = sns.lineplot(x='time', y=aa, data=new_df, color='r')
以下是:
ax[i,j] = sns.lineplot(x='time', y=aa, data=new_df, color='r')
一种方法是展平ax并遍历它们。您可以直接从matplotlib调用plt:
import pandas as pd
import matplotlib. pyplot as plt
dates = pd.date_range(start='1/1/2018', periods=10, freq='1D')
listA = [np.random.normal(0,1,10) for i in range(4)]
new_df = pd.DataFrame({'time':dates })
fig, ax = plt.subplots(2,2, figsize=(10,10), sharex=True)
ax = ax.flatten()
for i,aa in enumerate(listA):
ax[i].plot(new_df['time'], aa, color='r')
ax[i].set_xticklabels(new_df['time'], rotation = 45, ha="right",fontsize=7)
如果你真的想使用seaborn,它会是这样的:
fig, ax = plt.subplots(2,2, figsize=(10,10), sharex=True)
ax = ax.flatten()
for i,aa in enumerate(listA):
sns.lineplot(x=new_df['time'], y=aa, color='r',ax=ax[i])
ax[i].set_xticklabels(new_df['time'], rotation = 45, ha="right",fontsize=7)
一种方法是展平ax并遍历它们。您可以直接从matplotlib调用plt:
import pandas as pd
import matplotlib. pyplot as plt
dates = pd.date_range(start='1/1/2018', periods=10, freq='1D')
listA = [np.random.normal(0,1,10) for i in range(4)]
new_df = pd.DataFrame({'time':dates })
fig, ax = plt.subplots(2,2, figsize=(10,10), sharex=True)
ax = ax.flatten()
for i,aa in enumerate(listA):
ax[i].plot(new_df['time'], aa, color='r')
ax[i].set_xticklabels(new_df['time'], rotation = 45, ha="right",fontsize=7)
如果你真的想使用seaborn,它会是这样的:
fig, ax = plt.subplots(2,2, figsize=(10,10), sharex=True)
ax = ax.flatten()
for i,aa in enumerate(listA):
sns.lineplot(x=new_df['time'], y=aa, color='r',ax=ax[i])
ax[i].set_xticklabels(new_df['time'], rotation = 45, ha="right",fontsize=7)
有没有办法编辑x_轴标签格式?我需要'YYYY-MM-DD',而不是'yyy-MM-DD MM:HH:SS'df['time'].dt.strftime('%y-%m-%d')。请避免在原始问题之外提问有没有办法编辑x_轴标签格式?我需要'YYYY-MM-DD',而不是'yyy-MM-DD MM:HH:SS'df['time'].dt.strftime('%y-%m-%d')。请避免在你原来的问题之外提问。答案与解释更可接受+votable答案与解释更可接受+votable