0
得到這個函數的圖形,想要格式軸,使圖形從(0,0)開始,我怎麼寫傳說,所以我可以標籤哪條線屬於y1和哪個y2和標籤軸。如何在matplotlib.pyplot中格式化軸幷包含圖例?
import matplotlib.pyplot as plt
def graph_cust(cust_type):
"""function produces a graph of day agaist customer number for a given customer type"""
s = show_all_states_list(cust_type)
x = list(i['day']for i in s)
y1 = list(i['custtypeA_nondp'] for i in s)
y2 = list(i['custtypeA_dp']for i in s)
plt.scatter(x,y1,color= 'k')
plt.scatter(x,y2,color='g')
plt.show()
由於
'對於名爲ax的特定軸實例,使用plt.xlabel(「」)或者ax.set_xlabel(「」)「。 – Greg
您不必在'set_xlim()'方法中包含'ax.get_xlim()[1]'作爲第二個參數。要只改變左邊極限,可以包含kwarg'left',或者只給方法一個(位置)參數,即'ax.set_xlim(0.0)'。請參閱[文檔](http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_xlim)。 – hooy