Как вывести изображение на печать с нелинейной осью y с Matplotlib с помощью imshow?

Я волновал использование этого. Это - своего рода взлом, но это на самом деле работает вполне прилично.

единственная вещь - Вы, должны быть очень осторожными с Вашими точками с запятой.: D

var strSql:String = stream.readUTFBytes(stream.bytesAvailable);      
var i:Number = 0;
var strSqlSplit:Array = strSql.split(";");
for (i = 0; i < strSqlSplit.length; i++){
    NonQuery(strSqlSplit[i].toString());
}
9
задан Peter Mortensen 5 November 2009 в 09:51
поделиться

3 ответа

Have you tried to transform the axis? For example:

ax = subplot(111)
ax.yaxis.set_ticks([0, 2, 4, 8])
imshow(data)

This means there must be gaps in the data for the non-existent coordinates, unless there is a way to provide a transform function instead of just lists (never tried).

Edit:

I admit it was just a lead, not a complete solution. Here is what I meant in more details.

Let's assume you have your data in an array, a. You can use a transform like this one:

class arr(object):
    @staticmethod
    def mylog2(x):
        lx = 0
        while x > 1:
            x >>= 1
            lx += 1
        return lx
    def __init__(self, array):
        self.array = array
    def __getitem__(self, index):
        return self.array[arr.mylog2(index+1)]
    def __len__(self):
        return 1 << len(self.array)

Basically it will transform the first coordinate of an array or list with the mylog2 function (that you can transform as you wish - it's home-made as a simplification of log2). The advantage is, you can re-use that for another transform should you need it, and you can easily control it too.

Then map your array to this one, which doesn't make a copy but a local reference in the instance:

b = arr(a)

Now you can display it, for example:

ax = subplot(111)
ax.yaxis.set_ticks([16, 8, 4, 2, 1, 0])
axis([-0.5, 4.5, 31.5, 0.5])
imshow(b, interpolation="nearest")

Here is a sample (with an array containing random values):

alt text http://img691.imageshack.us/img691/8883/clipboard01f.png

8
ответ дан 4 December 2019 в 13:03
поделиться

You can look at matplotlib.image.NonUniformImage. But that only assists with having nonuniform axis - I don't think you're going to be able to plot adaptively like you want to (I think each point in the image is always going to have the same area - so you are going to have to have the wider rows multiple times). Is there any reason you need to plot the full array? Obviously the full detail isn't going to show up in any plot - so I would suggest heavily downsampling the original matrix so you can copy rows as required to get the image without running out of memory.

3
ответ дан 4 December 2019 в 13:03
поделиться

Если вы хотите, чтобы у обоих была возможность увеличения и сохранения памяти, вы можете нарисовать рисунок «вручную». Matplotlib позволяет рисовать прямоугольники (это будут ваши «прямоугольные пиксели»):

from matplotlib import patches
axes = subplot(111)
axes.add_patch(patches.Rectangle((0.2, 0.2), 0.5, 0.5))

Обратите внимание, что размеры осей не устанавливаются с помощью add_patch (), но вы можете сами установить для них нужные значения (axes.set_xlim ,…).

PS: Мне кажется, что ответ Thrope (matplotlib.image.NonUniformImage) действительно может делать то, что вы хотите, более простым способом, чем описанный здесь "ручной" метод!

2
ответ дан 4 December 2019 в 13:03
поделиться
Другие вопросы по тегам:

Похожие вопросы: