0
df = pd.DataFrame({
    'Week 1': [5000,5900,6500,3500,4000,5300,7900],
    'Week 2': [4000,3000,5000,5500,3000,4300,5900],
    'Week 3': [4000,5800,3500,2500,3000,5300,6000],
}) #Sales in INR

Instead of using

df.plot()
plt.xticks(df.index.tolist(), 
['Monday','Tuesday','Wednusday','Thursday','Friday','Saturday','Sunday'])

How to use xticks as a parameter in the df.plot(). I tried:

df.plot(xticks=['Monday','Tuesday','Wednusday','Thursday','Friday','Saturday','Sunday'])

but got error:

ConversionError: Failed to convert value(s) to axis units: ['Monday', 'Tuesday', 
'Wednusday', 'Thursday', 'Friday', 'Saturday', 'Sunday']  
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
  • It doesn't seem to be possible – see [this answer to a similar question](https://stackoverflow.com/a/30280076/7117003). – petezurich Sep 09 '22 at 17:30
  • check https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.html it has a parameter `xticks` –  Sep 09 '22 at 17:34
  • Sorry – what I meant was, that it doesn't seem to be possible to set the xtick **labels** in the function call (the xticks you obviously can set). Does the code in my answer help you achieve what you were looking for? – petezurich Sep 09 '22 at 19:00

1 Answers1

0

Set the ticks and the labels like so:

df = pd.DataFrame({
    'Week 1': [5000,5900,6500,3500,4000,5300,7900],
    'Week 2': [4000,3000,5000,5500,3000,4300,5900],
    'Week 3': [4000,5800,3500,2500,3000,5300,6000],
})

df.plot()
plt.xticks(ticks=df.index, 
           labels=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])
plt.show()

Output:

enter image description here

petezurich
  • 9,280
  • 9
  • 43
  • 57
  • 1
    I know it can be done like this. But I wanted to know whether it can done by the method specified in the question –  Sep 10 '22 at 03:32