2016-04-07 15 views
3

Bunun bir "yinelenen" soru olduğunu (Remove the x-axis ticks while keeping the grids (matplotlib)) biliyorum, ancak bulduğum yanıtlar sorunumu çözmedi. Bu arsa üretirEksen işaretlerini kaldırın ancak Matplolib/ggplot stilini kullanarak ızgarayı tutun

%matplotlib inline 

from matplotlib import pyplot as plt 
from matplotlib.lines import Line2D 

import bumpy 

data = numpy.random.randint(0, 100, size=(100,100)) 

plt.style.use('ggplot') 
plt.figure(figsize=(10,10)) 
plt.imshow(data) 

plt.savefig('myplot.pdf', format='pdf', bbox_inches='tight') 
plt.close() 

:

Ancak enter image description here

, ben herhangi bir kene olmadan bir arsa ile bitirmek istiyorum, sadece ızgara Örneğin

, bu kod var .

plt.figure(figsize=(10,10)) 
plt.imshow(data) 
plt.grid(True) 
plt.xticks([]) 
plt.yticks([]) 

Wich tüm kene ve ızgaralar kaldırmak: Sonra bu çalıştı çalışırsanız, en son

enter image description here

bu:

plt.figure(figsize=(10,10)) 
plt.imshow(data) 
ax = plt.gca() 
ax.grid(True) 
ax.set_xticklabels([]) 
ax.set_yticklabels([]) 
Ben yaklaştıkça

ama benim .pdf Hala arsa dışında bazı keneler var. İç ızgarayı tutmaktan nasıl kurtulurum?

enter image description here

cevap

4
from matplotlib import pyplot as plt 
import numpy 

data = numpy.random.randint(0, 100, size=(100,100)) 

plt.style.use('ggplot') 
fig = plt.figure(figsize=(10,10)) 
ax = fig.add_subplot(111) 
plt.imshow(data) 
ax.grid(True) 
for axi in (ax.xaxis, ax.yaxis): 
    for tic in axi.get_major_ticks(): 
     tic.tick1On = tic.tick2On = False 
     tic.label1On = tic.label2On = False 

plt.show() 
plt.savefig('noticks.pdf', format='pdf', bbox_inches='tight') 
plt.close() 
4

Sen keneler için bir renk bildirebilirsiniz.

from matplotlib import pyplot as plt 
import numpy 

data = numpy.random.randint(0, 100, size=(100,100)) 

plt.style.use('ggplot') 
fig = plt.figure(figsize=(10,10)) 
ax = fig.add_subplot(111) 
ax.imshow(data) 
ax.tick_params(axis='x', colors=(0,0,0,0)) 
ax.tick_params(axis='y', colors=(0,0,0,0)) 
plt.show() 

sonuçlanır:

Transparent ticks

bu durumda şeffaf bir de
İlgili konular