python - matplotlib 2d data with floating values ranges -


i keep struggling work want too, can't seem right way. issue following, have 2d data generated function of x, y i'm trying display on pylab.figure.

the input data looks like:

range1_labels = [0.002, 0.006, 0.010, 0.014, 0.018] range2_labels = [10, 25, 80] data_values = 2d array dimensions (len(x_values), len(y_values)) 

from using scipy's rectbivariatespline generate 600 x 600 values want display on pylab.figure generated data, having values x , y axis labels in intervals. attempts done far:

    axes = figure.gca()     img = axes.matshow(posteriori_data)     axes.set_title("interpolated values")      figure.colorbar(img)      axes.set_yticks(range(len(range2_labels)), range2_labels)     axes.set_xticks(range(len(range1_labels)), range1_labels) 

this attempt still gives me labels [0, 100, 200, 300, 400, 500] both axes.

another thing tries is:

    axes = figure.gca()     img = axes.matshow(posteriori_data, extent=(min(range1_labels), max(range1_labels),                                                 min(range2_labels), max(range2_labels)),                        aspect='auto')     axes.set_title("interpolated values")      figure.colorbar(img) 

this seems closer want. 'larger' axis labels generated , on zoom recomputed properly. in above example, labels range2 appear expected no labels generated range1.

any pointers?

regards

your issue range small, , tick locator not coping gracefully.

something like:

data = rand(600,600) extent = [.002, .018, 10, 80]  ax = gca() ax.matshow(data, extent=extent, aspect='auto') ax.get_xaxis().set_major_locator(matplotlib.ticker.linearlocator(5))  plt.draw() 

will want.

digging bit, seems happening, using matshow function tuned displaying matrices. locator sets maxnlocator has flag integer forces put ticks on integer values (doc). makes sense if plotting matrix. in case setting extent less 1 in range, not ticks.

an alternate solution use imshow

data = rand(600,600) extent = [.002, .018, 10, 80]  ax = gca() ax.imshow(data, extent=extent, aspect='auto', interpolation='nearest')  plt.draw() 

this matshow in fact (src), can copy features want keep implementation, , drop don't want.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -