Python Forum
Matplot / numpy noisy data problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matplot / numpy noisy data problem
#1
Hi there,
I seem to be having a weird issue with my python when using numpy, pandas and matplot lib. I have a basic time series data that is uploaded from a CSV, but when i plot it, the chart does not look like the chart should look (a standard time series line chart), instead it has tons of noise. The data is just the closing price of the S&P, but the chart doesnt look like it should and its making my analysis stall... see attached for some snippits of the issue. Ive included the export plot chart, the way it looks in excel/should look, and what the CSV file raw data looks like. Any help would be appreciated!

   
   
   
Reply
#2
Post the code for reading the csv file. Try plotting 1 month of data. Maybe the plot will reveal a problem, or demonstrate that there is not a problem.

I think the problem is you are reading one of your columns as a date, but not using the correct format. I can demonstrate this using pandas to create a csv file and read it back using the wrong date format.
import pandas as pd
import matplotlib.pyplot as plt

# Make a dataframe
dates = pd.date_range(start='1/1/2000', end='12/31/2022')
df = pd.DataFrame({"date": dates, "value": list(range(len(dates)))})

# Write to csv file using day first format
df.to_csv('data.csv', index=False, date_format='%d/%m/%Y')

# Read from csv without using day first
df2 = pd.read_csv('data.csv', parse_dates=["date"])

# Read from csv using day first
df3 = pd.read_csv('data.csv', parse_dates=["date"], dayfirst=True)

df.plot(x='date', y='value', title="Original Dataframe")
df2.plot(x='date', y='value', title='read_csv(dayfirst=False)')
df3.plot(x='date', y='value', title='read_csv(dayfirst=True)')
plt.show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem adding two numpy arrays djf123 2 2,106 Aug-09-2022, 08:31 PM
Last Post: deanhystad
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,155 Jul-11-2022, 08:54 PM
Last Post: Larz60+
  Error when running a matplot lib example aurelius_nero 3 6,919 Apr-24-2022, 01:24 PM
Last Post: Axel_Erfurt
  SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem quest 3 1,758 Jan-30-2022, 10:53 PM
Last Post: quest
  How to save Matplot chart to temp file? Morkus 2 4,546 Jun-12-2021, 10:52 AM
Last Post: Morkus
  Looking for data/info on a perticular data-proccesing problem. MvGulik 9 3,914 May-01-2021, 07:43 AM
Last Post: MvGulik
  remove weekends from matplot mr_byte31 3 4,513 Aug-10-2019, 08:37 AM
Last Post: DeaD_EyE
  Generate matplot animation on a link ambush 0 2,168 Apr-01-2019, 10:23 AM
Last Post: ambush
  Problem installing numpy and matplotlib achondrite 1 3,141 Jan-16-2019, 11:43 PM
Last Post: snippsat
  Cannot close matplot figure landlord1984 5 9,033 May-11-2018, 04:42 PM
Last Post: Aung_Myo_Htut

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020