Python 向matplotlib图形添加标签
具有以下代码:Python 向matplotlib图形添加标签,python,csv,numpy,matplotlib,Python,Csv,Numpy,Matplotlib,具有以下代码: import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates days, impressions = np.loadtxt('results_history.csv', unpack=True, delimiter=',',usecols=(0,1) , converters={ 0: mdates.strpdate2num('%d-%m-%y')})
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
days, impressions = np.loadtxt('results_history.csv', unpack=True, delimiter=',',usecols=(0,1) ,
converters={ 0: mdates.strpdate2num('%d-%m-%y')})
plt.plot_date(x=days, y=impressions, fmt="r-")
plt.title("Load Testing Results")
#params = {'legend.labelsize': 500,
#'legend.handletextpad': 1,
#'legend.handlelength': 2,
#'legend.loc': 'upper left',
#'labelspacing':0.25,
#'legend.linewidth': 50}
#plt.rcParams.update(params)
plt.legend("response times")
plt.ylabel("Date")
plt.grid(True)
plt.show()
图形已生成,但我不知道如何添加一些xy标签。生成的图形:
还尝试增大图例文本大小,但未显示文本。并且来自X轴的标签重叠。CSV文件:
01-05-14, 55494, Build 1
10-05-14, 55000, Build 2
15-05-14, 55500, Build 3
20-05-14, 57482, Build 4
25-05-14, 58741, Build 5
如何从csv中添加xytext并更改图例和X轴的格式?您需要,例如:
要调整x轴文字,可以添加:
fig=plt.figure() # below the import statements
...
fig.autofmt_xdate() # after plotting
要更改图例文本,请在打印函数中使用label参数:
plt.plot_date(x=days, y=impressions, fmt="r-",label="response times")
要增加图例字体大小,请执行以下操作:
plt.legend(fontsize='x-large')
您在一个问题中有效地问了三个问题。这将返回
AttributeError:'str'对象没有属性“toordinal”
。它也没有回答老年退休金计划其他部分的问题。
plt.legend(fontsize='x-large')