I downloaded a VLASS fits file and i'm trying to plot it without success.
The problem is, i think, the shape
print(image_data.shape)
which gives me (1, 1, 3722, 3722).
My code is:
import matplotlib.pyplot as plt
import numpy as np
from astropy.io import fits
from astropy.visualization import astropy_mpl_style
plt.style.use(astropy_mpl_style)
hdulist = fits.open("vla_test.fits")
hdu = hdulist[0]
plt.figure()
plt.imshow(hdu.data[0,0,:,:], cmap='Greys')
plt.colorbar()
I don't get any error but image doesn't show off and i get white (void) image.
I tried to download other files from the survey but i get same result.
Related
I am using matplotlib to generate matrices I can train on. I need to get to the raw figure data.
Saving and reading the .png works fine, but my code runs 10x longer. Another stack overflow asked a similar question and the solution was to grab the canvas, but that related logic generated a numpy error. Here is my mwe.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.transforms import IdentityTransform
px = 1/plt.rcParams['figure.dpi'] # pixel in inches
fig, ax = plt.subplots(figsize=(384*px, 128*px))
i = 756
plt.text(70, 95, "value {:04d}".format(i), color="black", fontsize=30, transform=IdentityTransform())
plt.axis('off')
plt.savefig("xrtv.png") # I dont want to do this ...
rtv = plt.imread("xrtv.png") # or this, but I want access to what imread returns.
gray = lambda rgb: np.dot(rgb[..., :3], [0.299, 0.587, 0.114])
gray = gray(rtv)
Disabling rendering was a good hint. Consider using a memory buffer to I/O rather than playing with strings. Here is a full example:
import numpy as np
import io
import matplotlib.pyplot as plt
from PIL import Image
# disable rendering and dump to buffer
plt.ioff()
fig,ax = plt.subplots()
ax.plot(np.sin(np.arange(100)))
buf = io.BytesIO()
fig.savefig(buf,format='RGBA')
# plot from buffer
shape = (int(fig.bbox.bounds[-1]),int(fig.bbox.bounds[-2]),-1)
img_array = np.frombuffer(buf.getvalue(),dtype=np.uint8).reshape(shape)
Image.fromarray(img_array)
Want to visualise coordinates from csv file by a heatmap, but only one axis is displayed in the graph and nothing else as the picture shows:
enter image description here
This is the code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
data = np.genfromtxt("plik.csv", delimiter=";", dtype = float)
np.reshape(data, (-1, 2))
print(data.shape)
plt.imshow(data, cmap='hot')
plt.show()
And data in the file is displayed like this:
0.000000; 0.045761
0.000000; 0.016499
0.000013; 0.010060
0.013995; 0.065568
0.014008; 0.060024
0.007376; 0.066706
0.020661; 0.062069
0.019254; 0.060543
0.028329; 0.079392
0.021810; 0.058398
0.025076; 0.067873
0.068878; 0.120970
There are 9585 lines in the file.
I am trying to get python to read a geoTIFF image but am having trouble trying to get the image to show.
import rasterio as r
import numpy as np
import matplotlib.pyplot as plt
FNF=r'D:\\Iceberg data\\RADARSAT\\RS2_SLC_geotif\\roi20m_RS2_20160415_153940_0004_FQ13_HHVVHVVH_SLC_470697_4660_12996414_Geo.tif\\'
raster = r.open(FNF)
print(raster)
raster.bounds
raster.height
raster.width
raster.transform
raster.get_transform()
raster.tags(1)
xmin=raster.bounds[0]
ymax=raster.bounds[3]
raster.read(1)
fig = plt.figure(1)
plt.title('SLC image') # this defines the title
plt.imshow(raster)
I get the error with imshow. What am I doing incorrectly?
When I do {i: dtype for i, dtype in zip(raster.indexes, raster.dtypes)} I get float32 out.
I am trying to format the matrix better. My current code gives me o/p in the format as seen in the image:
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(10,10))
plt.matshow(final.corr(), fignum = 1)
plt.xticks(range(len(final.columns)), final.columns)
plt.yticks(range(len(final.columns)), final.columns)
I have a piece of code which is inputting a total of 448 thumbnail images and i need to display them in with 64 rows and 7 columns. The code I have does this but the images are so small they are completely useless. I've attached the image and the code i currently have. Any suggestions as to how i can get them to display large enough to see?
import numpy as np
import pylab as plt
import csv
import os
import matplotlib.image as img
plt.close('all')
ID=np.array([])
cata=csv.reader(open('final_final_list.csv',"rU"))
for x in cata:
ID=np.append(ID,x[0])
plots_acc=np.array([])
for i in range(0,len(ID)):
plots_acc=np.append(plots_acc,'filt_image/'+ID[i]+'/'+'ugr.png') #appending the file location for each of the object filter images
plots_acc=np.append(plots_acc,'filt_image/'+ID[i]+'/'+'i1.png')
plots_acc=np.append(plots_acc,'filt_image/'+ID[i]+'/'+'z.png')
plots_acc=np.append(plots_acc,'filt_image/'+ID[i]+'/'+'Y.png')
plots_acc=np.append(plots_acc,'filt_image/'+ID[i]+'/'+'J.png')
plots_acc=np.append(plots_acc,'filt_image/'+ID[i]+'/'+'H.png')
plots_acc=np.append(plots_acc,'filt_image/'+ID[i]+'/'+'Ks.png')
text=(['ugr','i1','z','Y','J','H','Ks'])
print plots_acc
plt.figure()
for x in range(0,len(plots_acc)): #creating subplot of filter images
plt.subplot(64,7,x)
plots=img.imread(plots_acc[x])
plt.imshow(plots)
plt.axis('off')
#plt.suptitle(ID[i])
plt.subplots_adjust(hspace=0.0, wspace=0.0, bottom=0.63)
#plt.savefig('accepted object images/'+str(ID[i])+'.png')
plt.show()