简体   繁体   中英

Plotting two dataframe columns as xy-scatter plot not working with matplotlib/pandas

I posted earlier today with a question about a script I'm working on here . I now have things working, but I need to plot my data and am running into issues. No matter which method of plotting I try, I never get a plot. The 'closest' I've gotten is using hitTable.plot(x='qty', y='probit') , which just returns <AxesSubplot:xlabel='qty'> and no plot.

Simplified code is below, which replaces the original import of data from.csv, data manipulation, calculations, etc. with a direct reconstruction of the dataframe I'm working with.

import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels as sm
from scipy.stats import norm
from tkinter import filedialog
from tkinter import *

# initialize tkinter
root = Tk()
root.withdraw()

# bunch of code that was omitted for clarity

qtys = [1,10,20,50,100]
prop = [0.07142857142857142, 0.14285714285714285, 0.35714285714285715, 0.9285714285714286, 1.0]
probit = [0] * len(qtys)

# had to use this instead of creating the array, as the last value of the probit vector is 'inf' which throws an error if you try to include it directly
for idx, val in enumerate(qtys):
   probit[idx] = 5 + norm.ppf(prop[idx])

hitTable = np.vstack([qtys,prop,probit])
hitTable = np.reshape(hitTable, (3,5))
hitTable = hitTable.T
hitTable = pd.DataFrame(hitTable)
hitTable.columns=['qty','probability','probit']

hitTable.plot(x='qty', y='probit')

Which results in the aforementioned (and undesired) <AxesSubplot:xlabel='qty'> . I'm just trying to get an X,Y scatter plot of points where the X-values are the values contained in qtys and the y-values are those in probit . Can anyone help?

PS matplotlab is a dumpster fire

If you change the last line to

hitTable.plot.scatter(x='qty', y='probit')

it should work

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