0

Using Python: I am trying to make a scatter plot using .csv dataframes that visualizes FIM admission and discharge scores. I am able to make a scatter plot but am struggling to...

Make male scatter points: Blue, circle markers ("."), size 100, label "Male (N=)"

Make female scatter points: Red, plus markers ("+"), size 100, label "Female (N=)"

Y = X line: Black, dashed line style ("--"), x limits and y limits are [0, 140] My graph is supposed to read into my 'RIC' column but make a different graph for each instance within the column (for example 'repILE')

This is what it should look like: enter image description here

I have included the code I have so far:

patient_data_df.plot.scatter(x='Admission Total FIM Score', y= 'Discharge Total FIM Score', s=50, marker= "X", color= "green")

plt.title("FIM Scatter Plot:<RIC> (N=<total>)<RIC> (N=<total>)")

#plt.show()

1 Answer 1

1

It's better to use matplotlib instead pandas plot

Here example code:

import pandas as pd
from matplotlib import pyplot as plt

data = pd.DataFrame([[1.1, 4.2, 'Male'], [1.2, 3.3, 'Male'], [2.3, 3.2, 'Male'], [1.4, 7.1, 'Male'], [1.3, 3.2, 'Female'], [2.3, 2.2, 'Female'], [4.2, 1.8, 'Female']], columns=['Admission Total FIM Score', 'Discharge Total FIM Score', 'Sex'])

x_name = 'Admission Total FIM Score'
y_name = 'Discharge Total FIM Score'

plt.figure(figsize=(10, 8))
plt.plot([0, 5], [0, 5], 'k--', label='No Change')
plt.plot(data[data.Sex == 'Female'][x_name], data[data.Sex == 'Female'][y_name], 'r+', label='Female (N=%i)' % len(data[data.Sex == 'Female']))
plt.plot(data[data.Sex == 'Male'][x_name], data[data.Sex == 'Male'][y_name], 'b.', label='Male (N=%i)' % len(data[data.Sex == 'Male']))
plt.title('RepILE (N=%i)' % len(data))
plt.xlabel(x_name)
plt.ylabel(y_name)
plt.legend();

Output graph:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.