0

As you can see, px and py are arrays that contain 100 numbers from 0 to 1. But nevertheless, in the plot generated, the axis range is wrong (from 0 to 100 instead of from 0 to 1), and this bothers me a lot because I need to plot several curves in the same plot, and the next curve is not corresponding with the first because of the wrong axis values of the first. (My real data is a very huge dataset; I used the case of px and py as an useful example)

I will appreciate your help. Puravida.

The code I am using:

import numpy as np
px=np.linspace(0,1,100)
py=px
import matplotlib.pyplot as plt
import matplotlib.colors as colors
startcolor = '#FFFFFF'  # white
midcolor = '#FEDB8B'    # yellow
endcolor = '#FE9272'    # Orange
endcolor2 = '#723472'    # Purpple
colorsforCmap=[startcolor,midcolor,endcolor,endcolor2]
cmap2 = colors.LinearSegmentedColormap.from_list('own2',colorsforCmap)
plt.cm.register_cmap(cmap=cmap2)
plt.rcParams["figure.figsize"] = [12,9]
heatmap, xedges, yedges = np.histogram2d(px, py, bins=(100, 100))
plt.clf()
plt.imshow(heatmap.T, origin='lower',cmap=cmap2)
plt.show()

Wrong plot generated. Look at the axis values:

enter image description here

DavidG
  • 24,279
  • 14
  • 89
  • 82
  • 1
    They look fine to me. – Stop harming Monica Nov 02 '16 at 11:47
  • 1
    The axes go to 100 because `heatmap` is a 100 by 100 array (can confirm with `heatmap.shape`). This is to be expected since bin sizes are (100, 100). Unless you add the `extent` keyword, `plt.imshow` will display your data as "0-based (row, column) indices." See http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.imshow for more. – lanery Nov 03 '16 at 04:48

0 Answers0