Plotting Values in Python

433
March 17, 2017, at 06:03 AM

I am new to Python and I'm working on plotting values onto a graph. It seems easy but it is very hard to extract values from a CSV file.

Here is what is going on:

  • First, I do not need all values plotted. I have created a test excel sheet (CSV) to show you what I mean.

  • I also need a new line (on the graph for every new line on excel)

----denoted by the different color highlights

Lets look at the photo to get a better understanding

Highlighted:
Light Blue= x-values for entire graph.
Green= y-values for first line.
Red= y-values for 2nd line.
Purple= y-values for 3rd line.
Etc. 

I would like all these lines on one graph, and each line to be labeled with the values highlighted in grey (corresponding to the below set of y-values)

Here is what i have written so far, which isolated the values i need, I just do not know how to plot them.

Sorry for such a rough explanation Thank you

Answer 1

You should use pandas to read the csv file and matplotlib to plot the lines.

import pandas
import matplot.pyplot as plt
df = pandas.read_csv('./csv_file.csv')
fig, ax = plt.subplots()
ax.plot(df['Light Blue'], df['Green'], label='Green', color='green')
ax.plot(df['Light Blue'], df['Red'], label='Red', color='red')
ax.plot(df['Light Blue'], df['Purple'], label='Purple', color='purple')
ax.legend()

This is assuming the columns in the csv are labelled with 'Light Blue', 'Green', etc.

Rent Charter Buses Company
READ ALSO
spark.ml StringIndexer throws 'Unseen label' on fit()

spark.ml StringIndexer throws 'Unseen label' on fit()

I'm preparing a toy sparkml example

697
Python Webhook: Passing through a URL + payload

Python Webhook: Passing through a URL + payload

I'm a complete beginner with Python and trying to build a service that takes information from apiai, passes it to an API, then returns a confirmation message from the JSON it returns

461
How to Password protect Shared Drive files using Drive API

How to Password protect Shared Drive files using Drive API

I am developing industrial android applications that utilize the Google Drive API to both read from and write to files that are shared by the company G-Suite administratorThe applications are installed on an employees work profile and managed using Google...

324