我想在同一个图中绘制一个具有相同比例的线图和散点图,以及一个具有其他比例的条形图。 我可以得到两个子地块:
尽管如此,第一个子地块横坐标的记号标签应与第二个子地块横坐标的记号标签相同
这是我写的代码:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
excelname = 'mock.xlsx'
df = pd.read_excel(io = excelname, sheet_name = 'Transactions',
index_col = [0,1,2])
df.loc[:,'Volume'] = np.abs(df['Volume']) #volumes are non positive in the spreadsheet
df_price = pd.read_excel(io = excelname, sheet_name = 'Prix_fruits',
index_col = [0])
df_price_reset = df_price.melt(value_vars=df_price.columns, var_name = 'Prix', ignore_index = False).reset_index()
df_reset = df.reset_index()
sns.set_theme(style="white")
fig, ax = plt.subplots(2,1)
sns.lineplot(data = df_price_reset, x = 'StartDate', y = 'value', hue = 'Prix', dashes =False, palette = 'Pastel2', ax = ax[0], sort = False)
sns.scatterplot(data = df_reset, x = "TradeDate", y = "Price", hue = "Type", size ='Volume',
palette = 'Dark2', s = 10, ax = ax[0])
sns.barplot(data = df_reset, x = 'StartDate', y = 'Volume', hue = 'Type', palette = 'Pastel2', ax = ax[1], alpha = 0.5, ci = None)
fig, ax = plt.subplots()
sns.lineplot(data = df_price_reset, x = 'StartDate', y = 'value', hue = 'Prix', dashes =False, palette = 'Pastel2', ax = ax, sort = False)
sns.scatterplot(data = df_reset, x = "TradeDate", y = "Price", hue = "Type", size ='Volume',
palette = 'Dark2', s = 10, ax = ax)
ax2 = ax.twinx()
sns.barplot(data = df_reset, x = 'StartDate', y = 'Volume', hue = 'Type', palette = 'Pastel2', ax = ax2, alpha = 0.5, ci = None)
我怎样才能把这些情节合并在一起
目前没有回答
相关问题 更多 >
编程相关推荐