2016-04-23 1 views
1

Salut pour le terrain matplotlib ci-bas pour définir les titres des axes tels qu'ils montrent que les valeurs de l'axe x vont dePython Comment définir les axes pour une parcelle de matplotlib

2**-5, 2**-4, 2**-3,..., 2**14, 2**15 

et les valeurs de l'axe y cours de

2**-15, 2**-14,...., 2**4, 2**5 

Le graphique que je veux les afficher sur est:

The graph with the axes that needs changing

Le code pour le graphique est ci-dessous:

from matplotlib import pyplot 
import matplotlib as mpl 

import numpy as np 


zvals = 100*np.random.randn(21, 21) 
fig = pyplot.figure(2) 

cmap2 = mpl.colors.LinearSegmentedColormap.from_list('my_colormap', 
              ['blue','green','brown'], 
              256) 

img2 = pyplot.imshow(zvals,interpolation='nearest', 
        cmap = cmap2, 
        origin='lower') 

pyplot.colorbar(img2,cmap=cmap2) 
pyplot.show() 
+1

Avez-vous vérifié cela? (vous aurez peut-être besoin d'étiquettes): http://matplotlib.org/examples/ticks_and_spines/ticklabels_demo_rotation.html – Adib

+0

Et éventuellement dupliquer ici? http://stackoverflow.com/questions/3100985/plot-with-custom-text-for-x-axis-points – Adib

+0

Je ne veux pas étiqueter chaque cellule sur les axes car cela semblerait trop. –

Répondre

2

Vous pouvez utiliser un range avec un StepSize d'étiqueter tous les 5 cellules:

locs = range(0, N, 5) 
ax.set(xticks=locs, xlabels=...) 

Par exemple,

from matplotlib import pyplot as plt 
from matplotlib import colors as mcolors 
import numpy as np 


N = 21 
zvals = 100*np.random.randn(N, N) 
fig = plt.figure(2) 
ax = fig.add_subplot(111) 
cmap2 = mcolors.LinearSegmentedColormap.from_list(
    'my_colormap', ['blue','green','brown'], 256) 

img2 = plt.imshow(zvals,interpolation='nearest', 
        cmap=cmap2, origin='lower') 
plt.colorbar(img2, cmap=cmap2) 
step = 5 
locs = range(0, N, step) 
ax.set(
    xticks=locs, 
    xticklabels=['$2^{{{}}}$'.format(i-5) for i in locs], 
    yticks=locs, 
    yticklabels=['$2^{{{}}}$'.format(i-15) for i in locs]) 
plt.show() 

enter image description here