1

In the following expample I would like to assign the arguments passed to the plot in an appropriate datatype. Let his name be "plotargument". How do I assign plotargument correctly so I am able to get the same result from df.plot(plotargument) as from df.plot(x='Timestep', y='Position', figsize=(14,7),fontsize=15,grid=True).

An example usecase is to be found below:

import pandas as pd
from random import random

series=[0]
for x in range(0,2000):
    series.append(series[x]+1) if random()<0.5 else series.append(series[x]-1) 
df= pd.DataFrame({'Timestep' :[x * 200 for x in range(0,2001)], 'Position': series })

df.plot(x='Timestep', y='Position', figsize=(14,7),fontsize=15,grid=True)
Dr.Ario
  • 11
  • 5
  • 1
    One option would be to have it as a dict, then unpack it, eg: `plotargument = dict(x='Timestep', y='Position', figsize=(14,7),fontsize=15,grid=True)`... then use it as `df.plot(**plotargument)`... – Jon Clements Mar 07 '20 at 13:06
  • This should have been posted as an answer rather than a comment – Nicolas Gervais Mar 07 '20 at 13:20
  • @NicolasGervais not necessarily... it's still ambiguous as to what "safe the arguments passed to the plot" means - this was just a guess and a suggested attempt to make... Kind of hoping Dr.Ario elaborates on whether the comment above is something they can use or whether they were thinking something else... (eg: save to disk or database or maybe save the arguments *after* the plot has already been made... etc...) – Jon Clements Mar 07 '20 at 13:40
  • Thank you for the answer Jon. Your comment answers my question, especially with the doublestar syntax for passing the argument. I edited the question to remove the ambiguous part (hopefully). – Dr.Ario Mar 07 '20 at 13:44
  • Ah you're right. Well your answer was excellent if ever that's what OP needed – Nicolas Gervais Mar 07 '20 at 14:06

0 Answers0