I am seeking a better understanding of python plotting routines in pandas/matplotlib that cause xticklabels to disappear when formatting is attempted. To demonstrate, here is some basic code to recreate the problem:
#Create dummy variables x and y in a dataframe and plot in a scatter plot with the xticklabels rotated 35 degrees
data={'x':[1111,2222,3333,4444], 'y':[1211,1322,1260,5555]};
df=pd.DataFrame(data=data);
ax1=df.plot('x', 'y', kind='scatter', c='lightblue', s=50, edgecolors='black')
#Create dummy variables x and y in a dataframe and plot in a scatter plot with the xticklabels rotated 35 degrees
data={'x':[1111,2222,3333,4444], 'y':[1211,1322,1260,5555]};
df=pd.DataFrame(data=data);
ax1=df.plot('x', 'y', kind='scatter', c='lightblue', s=50, edgecolors='black')
This generates a generic plot with labeled x- and y- axes and x- and y- ticklabels. (generic x-y scatter plot with default axis and tickmark labels)
Now, if I want to rotate the xticklabels and horizontally align them to the right, that is where I run into the disappearing xticklabels:
#I would like to change the angle of rotation of the xticklabels of the ax1 handle.
labels=ax1.get_xticklabels()
print(labels)
ax1.set_xticklabels(labels, rotation=40)
ax1.set_xticklabels(labels, ha="right")
Now the xticklabels have disappeared. I've added a line to print the xticklabels because most examples perform the set_xticklabels when custom labels are being affixed to the plot. I just want to use what was already plotted. I think that the problem may lie in the contents of the 'labels' variable that I populated with get_xticklabels, but I am having trouble connecting the dots here. Any help understanding this will be greatly appreciated!