I have a question that continues something I asked previously, this time about how to change x ticks.
Let me repeat the set-up, so you don't have to go to the link. Suppose I have the following data:
data = {'Value': {('1', 1): 3.0,
('1', 2): 4.0,
('1', 3): 51.0,
('1', 4): 10.0,
('1', 5): 2.0,
('1', 6): 17.0,
('1', 7): 14.0,
('1', 8): 7.0,
('1', 9): 2.0,
('1', 10): 1.0}}
df=pd.DataFrame(data)
Let's say this represents values for something for the first ten days in January. I want to plot this data, so I use:
df.plot()
plt.show()
Now, suppose I have another data set that has values for a subset of these dates with slightly different values but the same index values:
df1 = df[df['Value']<10]
df1['Value'] = df1['Value']*2
Per the answer, I can overlay a scatter plot as:
ax = df.plot()
df1.reindex(df.index).plot(marker='o',linestyle='none',color='g', ax=ax)
In a more general example, where the x-axis represents the 365 days of the year (in non-leap years), how can I get the x ticks to represent the first day of each month? The best solution I could come up with is:
plt.xticks(np.arange(0,365,30),['1/1','2/1','3/1','4/1','5/1','6/1','7/1','8/1','9/1','10/1','11/1','12/1'])
Of course, this doesn't work exactly since the months aren't all 30 days. What is an easier/accurate way?