【问题标题】:Passing variable and string to the label field [duplicate]将变量和字符串传递给标签字段[重复]
【发布时间】:2020-03-21 08:48:05
【问题描述】:

我有以下代码:

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 

我希望能够在标签字段中同时传递变量和文本,但由于某种原因,我可以传递变量或字符串,但不能同时传递两者。反正我有可能两个都通过吗?

【问题讨论】:

标签: python python-3.x matplotlib


【解决方案1】:

你可以试试:

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

plt.title(f'newtitle{start}')

【讨论】:

    猜你喜欢
    • 2020-06-16
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    相关资源
    最近更新 更多