Colobar and change axis x and y labels

Hello,

I don't know if I can ask questions concerning matplotlib problems
in this email list ... just let me know that this is not the right place, if.

I have an image, which I can read and put into a figure. The image
has axis and I can even save the image. I have two issues:

1. Since it is an 512 x 512 pixel image, the x and y axis labels
go from 0 to 500. However, I don't want these labels, I want to
change them to, e.g., 0 .. 3400 and 0 .. 3400. How can I do this?

2. I tried to attach a color bar to the right of the image but without
success. Have you a hint?

The code can be found below, it is a rather simple one.

Thanks in advance for any help.

Pythphys.

···

*****************************************************************

import scipy
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

file_path = "path_to_file"

# The binary file is read
data = scipy.fromfile(file=file_path,dtype=scipy.int16)
data = data.byteswap()
# The file has 512 x 512 pixel
data.shape = 512, 512

# The following code works fine. However, I still need:
#
# - Color bar (plt.color() does not work)
# - The x and y labels are 0 ... 500 and 0 ... 500 <= I want to change these labels. How.

fig = plt.figure()
frame = plt.subplot(111)
frame.imshow(data)
frame.axis()
plt.xlabel('X (nm)')
plt.ylabel('Y (nm)')
plt.savefig("image")

Try using ‘xticks’ and ‘yticks’, those commands let you define the location and label fo your tick marks.

Example -

xticks( arange(5), ('0', '100', '200', '300', '400') )

Where the argument in arange is the number of tick labels you’re making

···

On Wed, Feb 15, 2012 at 10:56 AM, <Pythphys@…3969…> wrote:

Hello,

I don’t know if I can ask questions concerning matplotlib problems

in this email list … just let me know that this is not the right

place, if.

I have an image, which I can read and put into a figure. The image

has axis and I can even save the image. I have two issues:

  1. Since it is an 512 x 512 pixel image, the x and y axis labels

go from 0 to 500. However, I don’t want these labels, I want to

change them to, e.g., 0 … 3400 and 0 … 3400. How can I do this?

  1. I tried to attach a color bar to the right of the image but without

success. Have you a hint?

The code can be found below, it is a rather simple one.

Thanks in advance for any help.

Pythphys.


import scipy

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

import numpy as np

file_path = “path_to_file”

The binary file is read

data = scipy.fromfile(file=file_path,dtype=scipy.int16)

data = data.byteswap()

The file has 512 x 512 pixel

data.shape = 512, 512

The following code works fine. However, I still need:

- Color bar (plt.color() does not work)

- The x and y labels are 0 … 500 and 0 … 500 <= I want to change

these labels. How.

fig = plt.figure()

frame = plt.subplot(111)

frame.imshow(data)

frame.axis()

plt.xlabel(‘X (nm)’)

plt.ylabel(‘Y (nm)’)

plt.savefig(“image”)


Virtualization & Cloud Management Using Capacity Planning

Cloud computing makes use of virtualization - but cloud computing

also focuses on allowing computing to be delivered as a service.

http://www.accelacomm.com/jaw/sfnl/114/51521223/


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

This *alone* will not do, the image might be scaled badly. Add extent.

Try this:

fig = plt.figure()
frame = plt.subplot(111)
im=frame.imshow(data,extent=[0,3400,0,3400])
plt.xticks([0,3400]); plt.yticks([0,3400])
plt.xlabel('X (nm)')
plt.ylabel('Y (nm)')
plt.colorbar(im)

plt.show()

···

Le 16/02/2012 02:20, Alexa Villaume a écrit :

Try using 'xticks' and 'yticks', those commands let you define the location and label fo your tick marks.

==

Jerzy Karczmarczuk
Caen, France