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?

P.S. matplotlab is a dumpster fire



Read more here: https://stackoverflow.com/questions/66343067/plotting-two-dataframe-columns-as-xy-scatter-plot-not-working-with-matplotlib-pa

Content Attribution

This content was originally published by W. MacTurk at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: