X axis was inverted automatically and unexpectedly when plotting a series of data against another series of data using pandas. Please look at my code below. How can I ensure
You can enforce a direction for each plot:
(t,b)= ax.get_xlim() ## Added for clarity
if t > b:
ax.set_xlim((b,t))
or
if ax.xaxis_inverted():
ax.invert_xaxis()
(the latter just do the explicit three-line version, though.)
I asked this question on the issue tracker of pandas, and got answer.
daraframe.plot(..) is designed such that
For a scatter plot, I think the above design is not suitable. The only solution I can think of is to use plt.plot direclty.
cphlewis's workaround is also useful.
To invert the graph you can use
arr1 = [1,2,3,4,5]
arr2 = [9,8,4,3,8]
df = pd.Dataframe(arr1,arr2)
df.plot.barh()
if you also want to print the graph in sorting then you can use
df.sort_values().plot.barh()
To enlarge the size of graph you can use
df.sort_values().plot.barh(figsize=(10,20))