0

Im trying to plot some basic data that is read in from a h5 file. For context it is the area of change features detected in an image using a variety of thresholds. I can plot the data ok but the y axis was displaying the values using scientific notation. I was able to overcome this but now have an offset. I have tried a number of things but haven't been successful. Im not too familiar with matplotlib in terms of formatting axes and manipulating the details.

my code is as follows:

infile = 'myH5file.h5'
f = h5py.File(file, 'r')
dset = f['/DATA/DATA']
sum = []
threshold = ['1','2','3']

Th1 = dest[...,0]
Th1 = numpy.sum(Th1)
sum.append(Th1)

Th2 = dest[...,0]
Th2 = numpy.sum(Th2)
sum.append(Th2)

Th3 = dest[...,0]
Th3 = numpy.sum(Th3)
sum.append(Th3)

x = threshold
y = numpy.array(sum)
ax = plt.gca()
plt.scatter(x, y)
plt.ticklabel_format(style='plain', axis='y')
ax = plt.gca()
ax.set_yticklabels(ax.get_yticks())
plt.show()

This gives me the following output: My plot output

And as you can see, there is a negative offset to -50000000.

I would like to remove this so that the axis starts at 0.

Any help is greatly appreciated!!!

GeoMonkey
  • 1,615
  • 7
  • 28
  • 56
  • It looks like you _should_ be using scientific notation here. Also, using `ax.set_yticklabels(ax.get_yticks())` is an awful idea and some what dangerous. If you pan/zoom/change the limits after that call the tick labels will be wrong. – tacaswell Feb 09 '15 at 17:11
  • See http://stackoverflow.com/questions/14711655/how-to-prevent-numbers-being-changed-to-exponential-form-in-python-matplotlib-fi/14711866#14711866 – tacaswell Feb 09 '15 at 17:12
  • That must have been left in from something else I was doing. Its not in my final code – GeoMonkey Feb 10 '15 at 13:26

2 Answers2

1

You should be able to use ylimits to explicitely specify which range to display.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
1

To set the y-axis limits, you can use ax.set_ylim(lower_bound, upper_bound).

greschd
  • 606
  • 8
  • 19