x axis inverted automatically , unexpectedly when plotting series of data against series of data using pandas. please @ code below. how can ensure x axis pointing right? automatic inversion of x axis intended behavior of pandas? can disabled?
let me explain example below. 3 plots created. expect each 1 shows 45 degree line rising right. however, of them have 45 degree line falling right because x axis inverted automatically. appears whether x axis inverted or not depends on values plotted.
import pandas pd import numpy np import matplotlib.pyplot plt df2 = pd.dataframe(np.random.randn(10, 3), columns=["a", "b", "c"]) df3 = df2*1.1 df3.rename(columns={"a": "a*1.1", "b": "b*1.1", "c": "c*1.1"}, inplace=true) df23 = df2.join(df3) fig, ax_list = plt.subplots(1,3) ax=ax_list[0] df23[["a", "a*1.1"]].plot(ax=ax, x="a") ax.axis('equal') ax.set_title("(x,y)=(a,a*1.1)") print ax.get_xlim() ## added clarity ax=ax_list[1] df23[["b", "b*1.1"]].plot(ax=ax, x="b") ax.axis('equal') ax.set_title("(x,y)=(b,b*1.1)") print ax.get_xlim() ## added clarity ax=ax_list[2] df23[["c", "c*1.1"]].plot(ax=ax, x="c") ax.axis('equal') ax.set_title("(x,y)=(c,c*1.1)") print ax.get_xlim() ## added clarity
you can enforce direction each plot:
(t,b)= ax.get_xlim() ## added clarity if t > b: ax.set_xlim((b,t))
or
if ax.xaxis_inverted(): ax.invert_xaxis()
(the latter explicit three-line version, though.)