2016-09-28 83 views
2

我想繪製散點圖的大型數據集。 我想用matplotlib繪製單像素標記。 它似乎已經解決了。散點圖matplotlib中的單個像素標記

https://github.com/matplotlib/matplotlib/pull/695

但我無法找到如何讓單個像素標記一提。

我的簡化數據集(data.csv)

Length,Time 
78154393,139.324091 
84016477,229.159305 
84626159,219.727537 
102021548,225.222662 
106399706,221.022827 
107945741,206.760239 
109741689,200.153263 
126270147,220.102802 
207813132,181.67058 
610704756,50.59529 
623110004,50.533158 
653383018,52.993885 
659376270,53.536834 
680682368,55.97628 
717978082,59.043843 

我的代碼如下。

import pandas as pd 
import os 
import numpy 
import matplotlib.pyplot as plt 

inputfile='data.csv' 
iplevel = pd.read_csv(inputfile) 
base = os.path.splitext(inputfile)[0] 

fig = plt.figure() 
plt.yscale('log') 
#plt.xscale('log') 
plt.title(' My plot: '+base) 
plt.xlabel('x') 
plt.ylabel('y') 
plt.scatter(iplevel['Time'], iplevel['Length'],color='black',marker=',',lw=0,s=1) 
fig.tight_layout() 
fig.savefig(base+'_plot.png', dpi=fig.dpi) 

您可以在下面看到,點不是單個像素。

data_plot.png

任何幫助表示讚賞

回答

2

我擔心,在您所引用matplotlib git倉庫討論的bug修正僅適用於plt.plot()而不是plt.scatter()

import matplotlib.pyplot as plt 

fig = plt.figure(figsize=(4,2)) 
ax = fig.add_subplot(121) 
ax2 = fig.add_subplot(122, sharex=ax, sharey=ax) 
ax.plot([1, 2],[0.4,0.4],color='black',marker=',',lw=0, linestyle="") 
ax.set_title("ax.plot") 
ax2.scatter([1,2],[0.4,0.4],color='black',marker=',',lw=0, s=1) 
ax2.set_title("ax.scatter") 
ax.set_xlim(0,8) 
ax.set_ylim(0,1) 
fig.tight_layout() 
print fig.dpi #prints 80 in my case 
fig.savefig('plot.png', dpi=fig.dpi) 

enter image description here

2

對於任何人仍然試圖解決這個問題,soluti我發現是在plt.scatter中指定s參數。

s參數是指您正在繪製的點的面積。

它似乎並不完美,因爲s = 1似乎覆蓋了我屏幕的大約4個像素,但這絕對會使它們比我能找到的任何其他東西都小。

https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.scatter.html

S:標量或array_like,形狀(N),在點^ 2可選
大小。默認爲rcParams ['lines.markersize'] ** 2.