簡體   English   中英

Python plot 散點數據在 X 軸上表現不佳

[英]Python plot scatter data don't behave well on X axis

不確定如何解釋我的問題,基本上我正在嘗試 plot 一些東西:

plt.scatter(fichi_i,fre_i,c=duree_i, s=50,cmap='hot')

例如,“fichi_i”在哪里:

[10, 21, 25, 28, 36, 41, 48]

例如,我希望我的 X 軸從 0 到 500 開始。 怎么做? 沒有任何跡象表明 plot 從 10 變為 48。

已經嘗試過我在其他腳本中使用的以下內容:

plt.xlim(0,500)
    
ax.set_xticks(np.arange(0, 500, 50))

ax.set_xlim(0,500)    

plt.gca().set_xlim(left=0)

所有得到相同的結果:plot 仍然以 10 開始。

當我將前幾行中的“0”替換為“10”時,plot 從... 20 開始,所以它似乎做了一些事情,但就像這些命令中的“0”是第一個值“fichi_i”變量。 不是軸的實際 0,我設法通過使用而不是“0”找到了解決方法。 “-10”。 所以 x 軸從“0”開始……我不知道如何更改軸的最大值。

現在另一個問題是,在我的 plot 上,數組的點之間沒有“空間”。 就像“21”對應的點緊跟在“10”的點之后,它們之間沒有對應10個值的空白。 我這里的數組有“7”值,如果我將 X 軸的最大限制設置為 7,我會看到所有值。 如果我將它設置為 100,我有 7 個值和 93 個空白,從 48(這是第 7 個值)到 100。

基本上我怎么能說“x 軸從 0 到 100”並讓點到正確的位置,x 軸的第 10 個值上的 10,......它與 plot 一起工作正常但分散它是一場噩夢不知道為什么行為不一樣。

我用於 plot 順便說一句的代碼:

w, h = figaspect(1/3)
fig, ax = plt.subplots(1,figsize=(w,h))

plt.xlabel('test number')

plt.scatter(fichi_i,fre_i,c=duree_i, s=50,cmap='hot')
plt.colorbar(label='time(s)')
ylims = ax.get_ylim()
xlims = ax.get_xlim()  
plt.show()

謝謝。 我希望我的解釋很清楚,但我不確定如何解釋。

使用 plt.xlim(0, 500) 對我有用,我懷疑它被錯誤地放置在代碼中。 它必須介於:

fig , ax = plt.subplots(1, figsize=(w,h))

plt.show()

完整代碼:

import matplotlib.pyplot as plt
w, h = plt.figaspect(1/3)
fig, ax = plt.subplots(1,figsize=(w,h))
fichi_i = [10, 21, 25, 28, 36, 41, 48]
fre_i = [10, 21, 25, 28, 36, 41, 48]
duree_i = ['red' for _ in fre_i]
plt.xlabel('test number')

plt.scatter(fichi_i,fre_i,c=duree_i, s=50,cmap='hot')
plt.colorbar(label='time(s)')
ylims = ax.get_ylim()
xlims = ax.get_xlim()  
plt.xlim((10, 500))
plt.show()

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM