Python 3 Programming Tutorial – Matplotlib plotting from a CSV




[ad_1]

In this Python 3 tutorial, we cover how to plot in Matplotlib from a CSV file.

Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/

Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

Source


[ad_2]

Comment List

  • sentdex
    December 12, 2020

    thank you !

  • sentdex
    December 12, 2020

    …But what if you have an entire table, and you want to assign X and Y to a row and a column…

  • sentdex
    December 12, 2020

    Traceback (most recent call last):
    File "/Users/hedyeherfani/PycharmProjects/untitled15/assignment.py", line 7, in <module>
    x, y = np.loadtxt('world-population (1).csv', unpack=True, delimiter=',')
    File "/Users/hedyeherfani/.conda/envs/untitled15/lib/python3.7/site-packages/numpy/lib/npyio.py", line 1159, in loadtxt
    for x in read_data(_loadtxt_chunksize):
    File "/Users/hedyeherfani/.conda/envs/untitled15/lib/python3.7/site-packages/numpy/lib/npyio.py", line 1087, in read_data
    items = [conv(val) for (conv, val) in zip(converters, vals)]
    File "/Users/hedyeherfani/.conda/envs/untitled15/lib/python3.7/site-packages/numpy/lib/npyio.py", line 1087, in <listcomp>
    items = [conv(val) for (conv, val) in zip(converters, vals)]
    File "/Users/hedyeherfani/.conda/envs/untitled15/lib/python3.7/site-packages/numpy/lib/npyio.py", line 794, in floatconv
    return float(x)
    ValueError: could not convert string to float: 'Year'

    Another video that just doesn't help, great 🙂

  • sentdex
    December 12, 2020

    What ide is he using to code

  • sentdex
    December 12, 2020

    How would I do this, but with a histogram??

  • sentdex
    December 12, 2020

    ValueError: could not convert string to float: '"""'

  • sentdex
    December 12, 2020

    fuck sake error on line fucking one

  • sentdex
    December 12, 2020

    What if I have a file that has many labels on the first line, such as site_name,people,money,date? the next line are the values

  • sentdex
    December 12, 2020

    Best matplotlib series for beginner. Thank you so much for your tutorials.

  • sentdex
    December 12, 2020

    very helpfull!

  • sentdex
    December 12, 2020

    I am going to start the matplot series 😉 Thanks!!!

  • sentdex
    December 12, 2020

    can you run matplotlib without tkinter?

  • sentdex
    December 12, 2020

    Awesome, thanks

  • sentdex
    December 12, 2020

    Hallo thanks for the nice video. I have a file with date and time stamp and value. How i can plot that csv file using Matplotlib this will be realtime data with 1 second interval.
    I am using print command to print output of Raspberry pi GPIO Pin in Python 3.7

    My code is

    import time
    from time import sleep # Allows us to call the sleep function to slow down our loop
    import RPi.GPIO as GPIO # Allows us to call our GPIO pins and names it just GPIO

    GPIO.setmode(GPIO.BCM) # Set's GPIO pins to BCM GPIO numbering
    INPUT_PIN = 16 # Write GPIO pin number.
    GPIO.setup(INPUT_PIN, GPIO.IN) # Set our input pin to be an input
    # Start a loop that never ends
    while True:
    if (GPIO.input(INPUT_PIN) == True):
    # now i will have output as zero.
    print (time.strftime ("%Y/%m/%d , %H:%M:%S"),"0")
    else:
    #now i will have output as 200.
    print(time.strftime ("%Y/%m/%d , %H:%M:%S"),"200")
    sleep(1); # Sleep for a full second before restarting our loop

    print (time.strftime ("%Y/%m/%d , %H:%M:%S"),"0")
    (how i can make it better)
    Please help

    output of my csv file is
    date stamp time and print status is this
    ('2017/12/27 23:19:13' '0')
    ('2017/12/27 23:19:14' '200')
    ('2017/12/27 23:19:15' '200')
    !!! copied from excel !!!!

  • sentdex
    December 12, 2020

    Thank you so much!

  • sentdex
    December 12, 2020

    use np.loadtext(your \file \path \file.txt) dont forget to replace '' with '\' in ur path

  • sentdex
    December 12, 2020

    in my case it just says "erno 2: no such file or directory " what to do? any suggestions?

  • sentdex
    December 12, 2020

    thanks for the tutorials you helped a lot bro awesome very nice

  • sentdex
    December 12, 2020

    i am trying to plot a graph with approx 700 x and y points. i used xlrd lib to import excel data. when i plot it i am getting empty graph sheet. and when i reduce this points to 100 then it works perfectly. can u help me out to plot this data. if u hv alternative code then please let me knw

    import matplotlib.pyplot as plt
    import xlrd
    file=xlrd.open_workbook("/home/prakash/Desktop/UV result of nanomaterials1..xlsx")
    first_sheet = file.sheet_by_index(0)
    x=first_sheet.col_values(0)
    y=first_sheet.col_values(1)
    #print (x,y)
    plt.plot([x],[y], 'r')
    plt.axis([215.0, 800.0, 0, 2.000])
    #plt.show()

  • sentdex
    December 12, 2020

    I tried to my float data and it said about the delimiter (",") "too many values to unpack". Any solution sir?

  • sentdex
    December 12, 2020

    you made this mahd easy Thanks!

  • sentdex
    December 12, 2020

    best python video..thanks

  • sentdex
    December 12, 2020

    it says to me no module named matplotlib

  • sentdex
    December 12, 2020

    The CSV I'm using has text headers so I get an error when I run the code: "Could not convert string to float". Is there a way I can get the script to just read and handle integers for the plotting?

    Thanks in advance

  • sentdex
    December 12, 2020

    Thanks a lot for the video.
    I am receiving an error that name loadtxt is not defined.
    How can I resolve this? Thanks

  • sentdex
    December 12, 2020

    Hi Sentdex

    I am new to Python and I try to plots many CSV files on single plot :
    1. Read multiple (identically formatted) CSV files from a folder
    2. Plot column X 'time' vs column Y 'availability' from each of the CSV files on a single plot

    Please help me and thanks

  • sentdex
    December 12, 2020

    Hi , thanks for tutorial.
    I can't run the codes. It said syntax error: plt.plot(x, y, label = ('Loaded from file')

    Please kindly suggest.

  • sentdex
    December 12, 2020

    Great Tutorial ! I follow your video. But I want the output in .dxf file which can be open in any CAD software such Qcad, LibreCad. Can you suggest something for this?

Write a comment