Home > Software engineering >  how to multiply axis values by a factor of 100
how to multiply axis values by a factor of 100

Time:07-01

Both x and y scale values in this plot should be multiplied by 100.So that x-axis and y-axis values should be 0 2500 5000 7500 10000 12500 15000 17500 20000
My plot remains unchanged even after multiplying the data by that factor.

Input data https://www.file.io/GAYM/download/dDB51UAJdAG5

My code

import matplotlib.pyplot as plt
import numpy as np
data=np.loadtxt("input.txt")
plt.imshow(100*data,cmap='jet', interpolation='none')
plt.show()

CodePudding user response:

Multiplying the data doesn't help because your data only includes the pixel values but not the coordinates.

A quick and dirty hack is to modify the tick formatter:

def formatter(x, pos):
    del pos
    return str(x*100)

ax.xaxis.set_major_formatter(formatter)
ax.yaxis.set_major_formatter(formatter)

A more proper way is to use the extent keyword argument as explained in this tutorial but I don't have time right now to tailor that to turn that into an answer to your question. Maybe someone else (or you) does.

  • Related