[英]Python/Matplotlib - Adjusting the spacing between the edge of the plot and the x-axis
[英]spacing value between value in x-axis matplotlib using python
我有一個FPR和TPR圖。 在這里,我想問一下如何在x軸之間設置間距值。 我的代碼如下:
In [85]:
fig, ax = plt.subplots(figsize=(8,6), dpi=80)
ax.plot(x_iter1_TF , y_iter1_TF, label='Iter1', marker='o')
ax.plot(x_iter5_TF, y_iter5_TF ,label='Iter5', marker='v')
ax.plot(x_iter10_TF, y_iter10_TF , label='Iter10', marker='x')
ax.plot(x_iter25_TF, y_iter25_TF , label='Iter20', marker='+')
ax.plot(x_iter50_TF, y_iter50_TF , label='Iter50',marker='D')
ax.legend(loc=1); # upper left corner
ax.set_xlabel('FPR')
ax.set_ylabel('TPR')
ax.set_xlim([0,1, 0.001])
ax.set_ylim([0,1, 0.001])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-85-87b9ef379a9b> in <module>()
8 ax.set_xlabel('FPR')
9 ax.set_ylabel('TPR')
---> 10 ax.set_xlim([0,1, 0.001])
11 ax.set_ylim([0,1, 0.001])
C:\Python27\lib\site-packages\matplotlib\axes\_base.pyc in set_xlim(self, left, right, emit, auto, **kw)
2524
2525 if right is None and iterable(left):
-> 2526 left, right = left
2527
2528 self._process_unit_info(xdata=(left, right))
ValueError: too many values to unpack
在這里,我使用ax.set_xlim([0,1,0.001]),其中0.001是x軸之間的間隔值。 不幸的是,我遇到了一個錯誤。 我認為我以錯誤的方式設置了這些東西
如我的評論中所述, set_xlim
不接受“ step”參數。 另外,我認為您想要的方法是set_xticks
,可以按如下方式使用:
In [13]: import numpy as np
...: ticks = np.arange(0, 2, 0.1)
...: ax.set_xticks(ticks)
...: fig
並給出以下結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.