0

グラフ用にこの関数を取得しました。グラフが (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() 

ありがとう

4

1 に答える 1

0

を使用して、いずれかの軸に制限を設定できますplt.xlim(x_low, x_high)。上限を手動で設定したくない場合 (たとえば、現在の上限に満足している場合) は、次のことを試してください。

ax = plt.subplot(111) # Create axis instance
ax.scatter(x, y1, color='k') # Same as you have above but use ax instead of plt
ax.set_xlim(0.0, ax.get_xlim()[1])

ここでのわずかな違いに注意してください。軸インスタンスを使用します。これにより、これを使用して現在の xlimits を返すことができるようになりax.get_xlim()ます。(x_low, x_high)[1]

凡例の最小限の例:

plt.plot(x, y, label="テキスト") plt.legend()

凡例の詳細については、これらの例のいずれかを参照してください

于 2013-07-25T12:34:27.227 に答える