0

I have a python list which contains 4 elements, each of which is a time-series dataset. e.g.,

full_set = [Apple_px, Banana_px, Celery_px]

I am charting them via matplotlib and I want to save the charts individually using the variable names.

for n in full_set:

*perform analysis

    plt.savefig("Chart_{}.png".format(n))

The ideal output would have Chart_Apple_px, Chart_Banana_px, Chart_Celery_px as the chart names.

A1122
  • 1,324
  • 3
  • 15
  • 35

1 Answers1

0

In Python names and values are two very different things, stored and dealt with in different ways - and more practically one value can have multiple names assigned to it.

So, instead of trying to get the name of some data value, use a tuple where you assign a title to the dataset in your list of datasets, something like this:

full_set = [('Chart_Apple_px', Apple_px), ('Chart_Banana_px', Banana_px)]

for chart_name, dataset in full_set:
   # do your calculations on the dataset
   plt.savefig("{}.png".format(chart_name))
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284