1

I created a hexbin plot using the following code in Python:

df.plot(kind='hexbin', x='NO2', y='pre', gridsize=40, sharex = False)

and I get this figure,

figure 1

I want to change the ranges of input x and y from default to [0,100]. I used the following line:

ylim = [0, 100], xlim  =[0, 100] 

However, with these lines added my figure gets distorted and mapped to a 100 by 100 grid with blank spaces appear on edges as below.

figure 2

How can I change the input x and y range and not just distort the existing figure?

Amir H
  • 115
  • 12
  • You forgot to mention what you are expecting to see instead. I.e. what how do you want your final plot to look like? Since the result you see is absolutely expected, one would need to guess on what you don't like about it. – ImportanceOfBeingErnest Jun 30 '17 at 06:55
  • Dear @ImportanceOfBeingErnest, Thank you for your comment. I want ranges of x and y to be set to 0 to 100. Clearly this method is not the right way to do it. I am looking for a code to change ranges of x and y. – Amir H Jun 30 '17 at 12:44
  • I do not understand "Clearly this method is not the right way to do it". The range is 0 to 100 on both axes, so there is nothing wrong with this. – ImportanceOfBeingErnest Jun 30 '17 at 13:00
  • look at the figure @ImportanceOfBeingErnest, it has been streched horizontally and shrunk vertically which resulted in a blank area at the bottom. it should not be like that! – Amir H Jun 30 '17 at 13:08
  • Using this code, pre<20 has not been calculated and it is not shown in this figure. As you can see that area is blank. I want the area of pre<20 to be calculated and shown in the figure. – Amir H Jun 30 '17 at 13:16

1 Answers1

3

The extent keyword argument sets the range of values to include in the binning. So to have a hexbin plot with a range between 0 and 100 in both directions, you may use extent=[0,100,0,100],

df.plot(kind='hexbin',x='NO2',y='pre',gridsize=40, linewidths=0, extent=[0,100,0,100])
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712