PingjunChen
3/4/2018 - 3:39 PM

Save Matplotlib Figure as PDF

Save Matplotlib Figure as PDF

# -*- coding: utf-8 -*-
__author__ = "Pingjun Chen"
__email__ =  "chenpingjun@gmx.com"

import os, sys, pdb
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

with PdfPages('python_plt.pdf') as pdf:
    fig = plt.figure(figsize=(8, 8))  # Set image size
    plt.scatter(x_list, y_list)
    axes = plt.gca()
    axes.set_xlim([0, 3072])          # Set x limit
    axes.set_ylim([0, 3072])          # Set y limit

    plt.plot([512, 1024, 1536, 2048], [512, 1024, 1536, 2048], 'ro', markersize=5)
    plt.xlabel("Embolus width")       # Add x label
    plt.ylabel("Embolus height")      # Add y label
    plt.title("Embolus Size Distribution")  # Add title for plot
    # plt.tight_layout()              # Set tight layout
    pdf.savefig(fig)