I want to force a bar chart to have the x-axis in a certain order. But for some reason it always orders it alphabetically, I don't know why. Is there a setting I can use to keep it from doing that.
In the example below, I want the x-axis ordered as ['d', 'a', 'c', 'b']
. But it always orders it to ['a', 'b', 'c', 'd']
.
Code:
import pandas as pd
import matplotlib.pyplot as plt
ser = pd.Series([1,2,3,4], index=['d', 'a', 'c', 'b'])
fig = plt.bar(ser.index, ser.values, tick_label=ser.index)
Screenshot: