简体   繁体   中英

Getting matplotlib figure axes type

I wanted to plot a scatter from a csv data file (refer below).

在此处输入图片说明

I have already define for the plot and it already print the graph that I wanted.

def plot_calibration_curve(calib_data):
    plot = calib_data.plot(kind='scatter', x="conc X", y="Abs")
    plot.set_xlabel("$\mathrm{[X]\ /\ mol\ dm}^{-3}$")
    plot.set_ylabel('Absorbance')

plot_calibration_curve(calibration_data_X)

Plot output:

在此处输入图片说明

But when I ran this test, it gives a blank error;

assert isinstance(plot_calibration_curve(calibration_data_X), matplotlib.figure.Axes)
Output= AssertionError:

How do I get the matplotlib.figure.Axes type for this?

Your function

def plot_calibration_curve(calib_data):
    plot = calib_data.plot(kind='scatter', x="conc X", y="Abs")
    plot.set_xlabel("$\mathrm{[X]\ /\ mol\ dm}^{-3}$")
    plot.set_ylabel('Absorbance')

just plots, doesn't return anything. That is, it returns None . You will get True if you do

plot_calibration_curve(calib_data) is None

You want to try:

def plot_calibration_curve(calib_data):
    plot = calib_data.plot(kind='scatter', x="conc X", y="Abs")
    plot.set_xlabel("$\mathrm{[X]\ /\ mol\ dm}^{-3}$")
    plot.set_ylabel('Absorbance')

    # return
    return plot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM