Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用matplotlib和seaborn的两列子批次_Python_Subplot - Fatal编程技术网

Python 使用matplotlib和seaborn的两列子批次

Python 使用matplotlib和seaborn的两列子批次,python,subplot,Python,Subplot,我需要添加两列多行的子图。行不会固定,但对于一列,我想从一个数据集创建seaborn线图,对于第二列,我想为另一个数据集创建seaborn线图 我试过以下方法,但不起作用 tips = sns.load_dataset("tips") dataset2=tips days = list(tips.drop_duplicates('day')['day']) ggpec = gridspec.GridSpec(len(days ), 2) axs = [] for i,j in zip(day

我需要添加两列多行的子图。行不会固定,但对于一列,我想从一个数据集创建seaborn线图,对于第二列,我想为另一个数据集创建seaborn线图

我试过以下方法,但不起作用

tips = sns.load_dataset("tips")
dataset2=tips


days = list(tips.drop_duplicates('day')['day'])
ggpec = gridspec.GridSpec(len(days ), 2)
axs = []
for i,j in zip(days,range(1,len(days)+1)):
    fig = plt.figure(figsize=(20,4),dpi=200)
    palette = sns.color_palette("magma", 2)
    chart = sns.lineplot(x="time", y="total_bill",
                      hue="sex",style='sex',
                      palette=palette, data=tips[tips['day']==i])
    chart.set_xticklabels(
        chart.get_xticklabels(), 
        rotation=90, 
        minor=True,
        verticalalignment=True,
        horizontalalignment='right',
        fontweight='light',
        fontsize='large'
    )

    plt.title("Title 1",fontsize=18, fontweight='bold')

    fig2 = plt.figure(figsize=(20,5),dpi=200)
    palette = sns.color_palette("magma", 2)
    chart = sns.lineplot(x="time", y="total_bill",
                      hue="sex",style='sex',
                      palette=palette, data=dataset2[dataset2['day']==i])
    chart.set_xticklabels(
        chart.get_xticklabels(), 
        rotation=90, 
        minor=True,
        verticalalignment=True,
        horizontalalignment='right',
        fontweight='light',
        fontsize='large'
    )
    plt.title("Title 2",fontsize=18, fontweight='bold')
plt.show()

要创建包含两列和多行的多个绘图,可以使用子绘图。其中,定义当前要激活的行数、列数和子批数

import matplotlib.pyplot as plt
plt.subplot(3, 2, 1)   # Define 3 rows, 2 column, Activate subplot 1. 
plt.plot([1, 2, 3, 4, 5, 6, 7], [7, 8, 6, 5, 2, 2, 4], 'b*-', label='Plot 1')

plt.subplot(3, 2, 2)   # 3 rows, 2 column, Activate subplot 2.
# plot some data here
plt.plot([1, 2, 3, 4, 5, 6, 7], [7, 8, 6, 5, 2, 2, 4], 'b*-', label='Plot 2')

plt.subplot(3, 2, 3)   # 3 rows, 2 column, Activate subplot 3.
# plot some data here
plt.plot([1, 2, 3, 4, 5, 6, 7], [7, 8, 6, 5, 2, 2, 4], 'b*-', label='Plot 3')

# to Prevent subplots overlap
plt.tight_layout()  
plt.show()
你也可以在这个概念的基础上画出海生的情节

f, axes = plt.subplots(3,2) # Divide the plot into 3 rows, 2 columns
# Draw the plot in first row second column
sns.lineplot(xData, yData, data=dataSource, ax=axes[0][1]) 

要创建包含两列和多行的多个绘图,可以使用子绘图。其中,定义当前要激活的行数、列数和子批数

import matplotlib.pyplot as plt
plt.subplot(3, 2, 1)   # Define 3 rows, 2 column, Activate subplot 1. 
plt.plot([1, 2, 3, 4, 5, 6, 7], [7, 8, 6, 5, 2, 2, 4], 'b*-', label='Plot 1')

plt.subplot(3, 2, 2)   # 3 rows, 2 column, Activate subplot 2.
# plot some data here
plt.plot([1, 2, 3, 4, 5, 6, 7], [7, 8, 6, 5, 2, 2, 4], 'b*-', label='Plot 2')

plt.subplot(3, 2, 3)   # 3 rows, 2 column, Activate subplot 3.
# plot some data here
plt.plot([1, 2, 3, 4, 5, 6, 7], [7, 8, 6, 5, 2, 2, 4], 'b*-', label='Plot 3')

# to Prevent subplots overlap
plt.tight_layout()  
plt.show()
你也可以在这个概念的基础上画出海生的情节

f, axes = plt.subplots(3,2) # Divide the plot into 3 rows, 2 columns
# Draw the plot in first row second column
sns.lineplot(xData, yData, data=dataSource, ax=axes[0][1]) 
请阅读-总结是,这不是一个理想的方式来解决志愿者,可能会适得其反获得答案。请不要将此添加到您的问题中。请阅读-总结是,这不是解决志愿者问题的理想方式,可能会对获得答案产生反作用。请不要将此添加到您的问题中。