我需要将这两个图放在一起,但是当我使用条形图(主要)然后使用折线图(次要)时,它工作得很好。如果我改变关于情节的代码行中的顺序,它就不起作用。
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
flatui1 = ["#0C6514", "#18AB25"]
flatui2 = ["#0E1D56", "#18AB25"]
colors = sns.color_palette(flatui1)
cmap1 = LinearSegmentedColormap.from_list("my_colormap", colors)
colors = sns.color_palette(flatui2)
cmap2 = LinearSegmentedColormap.from_list("my_colormap", colors)
sns.set_style(style='whitegrid')
m1_t = pd.DataFrame({
"A":[0.21,0.05,1.22,0.41,1.28,1.15,0.91,0.63,0.38,1.18],
"B":[13.33,18,23.69,21.46,35.31,16,20.11,15.87,20.53,17.71],
"C":[5.71,2,23.44,9.02,35.39,13.48,14.62,13.17,13.68,14.66]
})
# This two line sequence has the problem
m1_t['A'].plot(kind='bar',colormap=cmap1)
m1_t[['B','C']].plot(kind='line',secondary_y=True,colormap=cmap2)
ax = plt.gca()
ax.grid(True)
ax.set_axisbelow(True)
ax.set_xticklabels(('P0', 'P1','P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9'))
plt.savefig('Comparison',dpi=300)
plt.show()
https://i.stack.imgur.com/I9yXy.png
饮歌长啸
忽然笑