Beispiel #1
0
# Define PNG file name and check if it exists already ...
pfile = "sunsetDiff.png"
if not os.path.exists(pfile):
    print("Making \"{:s}\" ...".format(pfile))

    # Create short-hand ...
    cm = matplotlib.pyplot.get_cmap("jet")

    # Make image ...
    img = numpy.zeros((lat.size, lon.size, 3), dtype=numpy.uint8)

    # Loop over y-axis ...
    for iy in range(lat.size):
        # Loop over x-axis ...
        for ix in range(lon.size):
            # Find normalized value ...
            val = min(1.0, max(0.0, diff[iy, ix] / 24.0))

            # Determine colours ...
            r, g, b, a = cm(val)

            # Set pixel ...
            img[iy, ix, 0] = 255.0 * r
            img[iy, ix, 1] = 255.0 * g
            img[iy, ix, 2] = 255.0 * b

    # Save PNG ...
    pyguymer3.save_array_as_PNG(img, pfile, ftype_req=0)
    pyguymer3.optimize_image(pfile, strip=True)
Beispiel #2
0
        labels.append("{:.1f} km".format(0.001 * dist))
        lines.append(
            matplotlib.lines.Line2D([], [], color=cmap(float(i) / 5.0)))

    # Draw background image ...
    ax.imshow(
        matplotlib.pyplot.imread("OrdnanceSurveyBackgroundImages/" +
                                 meta["MiniScale_(mono)_R22"]["greyscale"]),
        cmap="gray",
        extent=meta["MiniScale_(relief1)_R22"]["extent"],
        interpolation="bicubic",
        origin="upper",
        transform=cartopy.crs.OSGB(),
        vmin=0.0,
        vmax=1.0)

    # Add legend and save figure ...
    ax.legend(lines,
              labels,
              bbox_to_anchor=(1.0, 0.5),
              fontsize="small",
              ncol=1)
    fg.savefig(stub + ".png", bbox_inches="tight", dpi=dpi, pad_inches=0.1)
    if not debug:
        pyguymer3.optimize_image(stub + ".png", strip=True)
    matplotlib.pyplot.close(fg)

    # Stop looping if debugging ...
    if debug:
        break