Create geotiff from png or tif file

Hi,
I have created tif image using matplotlib python trigulation function, Now tif need to be change to goetiff with epsg4326 projection with removing the background only the patch need to be there.

What difficulty i am facing :- 1- projection change is not happening correct. 2- pixel value should be z parameter value. 3- only the clip of lat lon i want not the whole lat lon area.

CODES:- 1- For creating matplotlib trigulation tiff code below

    #MAKING TIFF FILE USING TRIANGULARION MATPLOTLIB.
    import matplotlib.tri as mtri
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt

    def plot():

            x=np.random.uniform(70,94,74)
            y=np.random.uniform(8,22,74)

            # A selected triangulation of the points.
            triangles = np.asarray([
                [67, 66, 1], [65, 2, 66], [1, 66, 2], [64, 2, 65], [63, 3, 64],
                [60, 59, 57], [2, 64, 3], [3, 63, 4], [0, 67, 1], [62, 4, 63],
                [57, 59, 56], [59, 58, 56], [61, 60, 69], [57, 69, 60], [4, 62, 68],
                [6, 5, 9], [61, 68, 62], [69, 68, 61], [9, 5, 70], [6, 8, 7],
                [4, 70, 5], [8, 6, 9], [56, 69, 57], [69, 56, 52], [70, 10, 9],
                [54, 53, 55], [56, 55, 53], [68, 70, 4], [52, 56, 53], [11, 10, 12],
                [69, 71, 68], [68, 13, 70], [10, 70, 13], [51, 50, 52], [13, 68, 71],
                [52, 71, 69], [12, 10, 13], [71, 52, 50], [71, 14, 13], [50, 49, 71],
                [49, 48, 71], [14, 16, 15], [14, 71, 48], [17, 19, 18], [17, 20, 19],
                [48, 16, 14], [48, 47, 16], [47, 46, 16], [16, 46, 45], [23, 22, 24],
                [21, 24, 22], [17, 16, 45], [20, 17, 45], [21, 25, 24], [27, 26, 28],
                [20, 72, 21], [25, 21, 72], [45, 72, 20], [25, 28, 26], [44, 73, 45],
                [72, 45, 73], [28, 25, 29], [29, 25, 31], [43, 73, 44], [73, 43, 40],
                [72, 73, 39], [72, 31, 25], [42, 40, 43], [31, 30, 29], [39, 73, 40],
                [42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38],
                [33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]])
            z = np.random.uniform(0.5, 8, 74)

            triang = mtri.Triangulation(x, y, triangles=triangles)
            print("type(triang):", triang)
            print("type(z):", type(z))

            ax=plt.tripcolor(triang,z,vmin=0,vmax=2)
            ax
            plt.savefig("ax.tif")
            plt.show(ax)
            
    plot()
    ```

#output tiff file 
![image|640x480](upload://dB1iR1aecSviCTl7QLF1vbpBr38.png) 

#Reading and plotting this generated tif file
    # checking first tiff file only

    import rasterio
    from rasterio.plot import show
    fp = r'16nov_first.tif'
    img = rasterio.open(fp)
    show(img)
![image|690x299](upload://npR2iiEmK51LTtcYRLVbojgn4RC.png) 

**Yellow color is plotted due to 255 value data array in .tiff file. As you can see i want to write code to :- 1- Remove that yellow color. 2- set projection and pixel size. 3- change my data from RGB to integer. For example from 255 to 4 Thank you.**
**Kindly please let me know how to create geotiff from png or tiff file with projection and removing the background color. I will really appreciate it.**

I think you posted this to the wrong forum - this is GMT not matplotlib.

Hi @sameerCoder, I recommend checking out rioxarray (https://corteva.github.io/rioxarray/stable/examples/convert_to_raster.html) and/or rasterio (https://rasterio.readthedocs.io/en/latest/quickstart.html#creating-data) to save your numpy array to a GeoTiff.