得到了这个图形的函数,想要格式化轴,使图形从(0,0)开始,我如何写图例,这样我可以标记哪条线属于y1,哪个属于y2,并标记轴。在
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()
谢谢
您可以使用
plt.xlim(x_low, x_high)
设置任意轴上的限制。如果您不想手动设置上限(例如您对当前上限满意),请尝试:注意这里的细微差别,我们使用一个axis实例。这使我们能够使用
ax.get_xlim()
返回当前的xlimit。这将返回一个元组(x_low, x_high)
,我们使用[1]
选择第二个元组。在一个最小的图例示例:
在plt.绘图(x,y,label=“一些文本”) plt.图例()
有关图例的详细信息,请参见any of these examples
相关问题 更多 >
编程相关推荐