0

I have the following code:

import pandas as pd
from pandas_datareader import data as web
import numpy as np
from scipy.stats import nbinom
import matplotlib.pyplot as plt
import datetime

data = web.get_data_yahoo('^GSPC', start, end)
data.plot(y='Close')
plt.title("newtitle " +start) <--- I want a string and pass a variable to the title 

I want to be able to pass a variable and text at the same time in the label fields but for some reason i can pass either a variable or a string but not both. Is there anyway it is possible for me to be able to pass both?

Slartibartfast
  • 1,058
  • 4
  • 26
  • 60
  • 1
    Check this answer: https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-inside-a-string – Magofoco Nov 26 '19 at 01:20

1 Answers1

2

You can try doing:

plt.title("newtitle{0}".format(start))

or

plt.title(f'newtitle{start}')
Magofoco
  • 5,098
  • 6
  • 35
  • 77