绘制图例乱序

时间:2018-09-10 02:47:34

标签: python pandas matplotlib

我有一个简单的问题:我的其中一个地块的图例出了问题。 而不是按照0,10,12,20(这是我绘制和标记数据的顺序)的顺序,而是按10,0,12,20的顺序。

这是我用来绘制的代码:

# Plot 0.05% Xanthan in NaCl - Elasticity
%matplotlib
ax_X05_E_All = WomboCombo_X05_E_Water.iloc[0:15].plot(x="Shear Stress 1", y="G' Average", yerr="G' Err", color='b', marker='o',ms=5, mfc="b",ecolor='r',capsize=2, loglog=True, label= "0 mMol NaCl   - G'")
WomboCombo_X05_E_Water.iloc[0:15].plot(x="Shear Stress 1", y='G" Average', yerr='G" Err', color='b', marker='o',ms=5, mfc="none",ecolor='r',capsize=2, ax=ax_X05_E_All, label= '0 mMol NaCl   - G"')

WomboCombo_X05_E_10mMol_NaCl.iloc[0:15].plot(x="Shear Stress 2", y="G' 2",  color='g', marker='o',ms=5, mfc="g",loglog=True,ax=ax_X05_E_All, label= "10 mMol NaCl - G'")
WomboCombo_X05_E_10mMol_NaCl.iloc[0:15].plot(x="Shear Stress 2", y='G" 2',  color='g', marker='o',ms=5, mfc="none",ax=ax_X05_E_All,  label= '10 mMol NaCl - G"')

WomboCombo_X05_E_12mMol_NaCl.iloc[0:15].plot(x="Shear Stress 1", y="G' Average", yerr="G' Err", color='orange', marker='o',ms=5, mfc="orange",ecolor='r',capsize=2, loglog=True, label= "12 mMol NaCl - G'", ax=ax_X05_E_All)
WomboCombo_X05_E_12mMol_NaCl.iloc[0:15].plot(x="Shear Stress 1", y='G" Average', yerr='G" Err', color='orange', marker='o',ms=5, mfc="none",ecolor='r',capsize=2, label= '12 mMol NaCl - G"', ax=ax_X05_E_All)

WomboCombo_X05_E_20mMol_NaCl.iloc[0:15].plot(x="Shear Stress 1", y="G' Average", yerr="G' Err", color='r', marker='o',ms=5, mfc="r",ecolor='r',capsize=2, loglog=True, label= "20 mMol NaCl - G'", ax=ax_X05_E_All)
WomboCombo_X05_E_20mMol_NaCl.iloc[0:15].plot(x="Shear Stress 1", y='G" Average', yerr='G" Err', color='r', marker='o',ms=5, mfc="none",ecolor='r',capsize=2, label= '20 mMol NaCl - G"', ax=ax_X05_E_All)

ax_X05_E_All.legend(bbox_to_anchor=(1.0, .69))


ax_X05_E_All.set_xlabel(r"$\tau$ (Oscillatory) [Pa]", size=20)
ax_X05_E_All.set_ylabel(r"""G' and G" [Pa]""", size=20)
ax_X05_E_All.set_title(""""G' and G" vs Shear Stress (Oscillatory) - Xanthan Gum 0.05% \n WT""",size=30)

filename = """G' and G" vs Shear Stress - 0.05% Xanthan in All Solutions"""
plt.savefig(filename + ".png",bbox_inches='tight',pad_inches=.1,dpi=250)

这是结果:

这是一条有8条线的地块,图例乱序

如果我注释掉代码行:

ax_X05_E_All.legend(bbox_to_anchor=(1.0, .69))

我得到这个情节:

图例是按顺序排列的,但缺少重要特征(空白点与实心圆)

我有7个相似的地块,其中的图例正确排序,并且几乎与该图例完全相同。

任何人都可以向我解释发生了什么,并帮助我找出一种可以让我正确订购图例的解决方案吗?

0 个答案:

没有答案
相关问题