'Resizing the figure in python and then editing x ticks does not work
I have a pandas dataframe and I am trying to plot a line. The plotting is fine but I have issues with the x-ticks labels because I want to supply my own, and I want to modify the figure size so its width can take all the ticks without overlapping issues (rotation is not enough). The problem I am facing is that when I resize the figure, it creates a new empty figure (with no plots) rather than modifying the one with the plots. It does adds the x-ticks correctly but in a separate figure. How to solve this issue? Below is my code:
dataset = read_csv('bbm.csv', header=0) #index_col=0)
#dataset=dataset.head(20)
raw_values = dataset.values
#dataset.columns
print(dataset.head())
ax=dataset.plot(x="Date", y=["US","Papers"]);
x=dataset['Date']
m=dataset['Month']
num_elements = len(x)
X_Tick_List = []
X_Tick_Label_List=[]
for item in range (0,num_elements):
X_Tick_List.append(item)
X_Tick_Label_List.append(m[item])
pyplot.figure(figsize=(20,5))
pyplot.xticks(ticks=X_Tick_List,labels=X_Tick_Label_List, rotation=0,fontsize=8)
pyplot.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
