brittAnderson / Intro2Computing4Psychology

A guided introduction to computing tools useful for research in psychology - targeted to complete beginners
47 stars 159 forks source link

Plotting in python #45

Closed katevk closed 3 years ago

katevk commented 3 years ago

Hello, I am working on the plotting in python but I get this error "AttributeError: 'Series' object has no attribute 'figure'" that I don't understand and I can't find anything online to help. I am don't have figure written in my code so I'm not sure what needs to be fixed. Any direction would be appreciated! Thank you in advance.

Here is my code and the associated error for reference. figure error

valeriemelanson commented 3 years ago

Hi Kate, I created my python plot a little differently and I don't know what that error message means if I'm being honest. However, I did find a link to a tutorial that uses the same packages that you're using here: https://medium.com/swlh/introduction-to-data-visualization-with-matplotlib-in-python-e9fb25276829 - hopefully this helps!

crachmad commented 3 years ago

Hi Kate, I also did it in a different way and I'm not quite sure what the error means. I found these sources: https://www.statsmodels.org/stable/examples/notebooks/generated/categorical_interaction_plot.html https://www.statsmodels.org/stable/generated/statsmodels.graphics.factorplots.interaction_plot.html hopefully, this can help you in solving your problem!

brjbrown commented 3 years ago

Hi there Kate, after looking around online a bit, this post which talks about simplifying things using a NumPy array might be the best solution for you. I've used NumPy a bunch in the past and it is usually fairly straightforward, and there's a lot of resources online about it.

Hope that helps!

katevk commented 3 years ago

I got it thank you!!!

brittAnderson commented 3 years ago

@katevk can you post what you did to fix your error for anyone else who comes along. Then you can close it again.

And I think it is great that an issue gets opened up, commented on, and closed all without my involvement. Great job you guys. Would you have seen that happening in September?

katevk commented 3 years ago

I determined that the interaction_plot function was messing up my results. I ended up fixing it like so.

from matplotlib import pyplot as plt import random import pandas as pd import numpy as np x = (random.sample(range(10,30),10)) y1 = (np.power(x,2)) y2 = (2 y1) y3 = (random.sample(range(10, 30), 10)) df=pd.DataFrame({ 'this is x': (random.sample(range(10,30),10)), 'this is y1':(np.power(x,2)), 'this is y2':(2 y1), 'this is y3':random.sample(range(10, 30), 10) }) lines = df.plot.line()