plotting multiple graph from a csv file and output to a single pdf/svg

2024/10/15 9:25:03

I have some csv data in the following format.

Ln    Dr    Tag Lab    0:01    0:02    0:03    0:04    0:05    0:06    0:07    0:08   0:09
L0   St     vT  4R       0       0       0       0       0      0        0       0      0
L2   Tx     st  4R       8       8       8       8       8      8        8       8      8
L2   Tx     ss  4R       1       1       9       6       1      0        0       6      7

I want to plot a timeseries graph using the columns (Ln , Dr, Tg,Lab) as the keys and the 0:0n field as values on a timeseries graph.

I have the following code.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as npplt.ylabel('time')
plt.xlabel('events')plt.grid(True)
plt.xlim((0,150))
plt.ylim((0,200))a=pd.read_csv('yourfile.txt',delim_whitespace=True)
for x in a.iterrows():x[1][4:].plot(label=str(x[1][0])+str(x[1][1])+str(x[1][2])+str(x[1][3]))plt.legend()
fig.savefig('test.pdf')

I have only shown a subset of my data here. I have around 200 entries (200 rows) in my full data set. the above code plots all graphs in a single figure. I would prefer each row to be plotted in a separate graph.

Answer

Use subplot()

import matplotlib.pyplot as pltfig = plt.figure()plt.subplot(221) # 2 rows, 2 columns, plot 1
plt.plot([1,2,3])plt.subplot(222) # 2 rows, 2 columns, plot 2
plt.plot([3,1,3])plt.subplot(223) # 2 rows, 2 columns, plot 3
plt.plot([3,2,1])plt.subplot(224) # 2 rows, 2 columns, plot 4
plt.plot([1,3,1])plt.show()fig.savefig('test.pdf')

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot

https://en.xdnf.cn/q/117851.html

Related Q&A

parallel python: just run function n times [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 9…

how to specify the partition for mapPartition in spark

What I would like to do is compute each list separately so for example if I have 5 list ([1,2,3,4,5,6],[2,3,4,5,6],[3,4,5,6],[4,5,6],[5,6]) and I would like to get the 5 lists without the 6 I would do …

Keeping just the hh:mm:ss from a time delta

I have a column of timedeltas which have the attributes listed here. I want the output in my pandas table to go from:1 day, 13:54:03.0456to:13:54:03How can I drop the date from this output?

How to return the index of numpy ndarray based on search?

I have a numpy 2D array, import numpy as np array1 = array([[ 1, 2, 1, 1],[ 2, 2, 2, 1],[ 1, 1, 1, 1],[1, 3, 1, 1],[1, 1, 1, 1]])I would like to find the element 3 and know its location. So,…

Python:Christmas Tree

I need to print a Christmas tree that looks like this:/\ / \ / \Here is my code so far:for count in range (0,20):variable1 = count-20variable2 = count*2print({0:{width1}}{1:{width2}} .format(/,\\,…

Send back json to client side

I just started developing with cherrypy, so I am struggling a little bit. In client side I am selecting some data, converting it to json and sending to server side via post method. Then I am doing a fe…

Can I use PyInstaller from Python 2.7 to compile an executable for a Python 3 script?

So, I tried installing PyInstaller in my Python 3.4 dir but, for some reason, Ive been getting errors and Im not able to install it. I however, do have a working PyInstaller in my Python 2.7 dir. I nee…

exporting different lists to .txt in python

I have a few lists which I all want to export to the same .txt file. So far I only export 3 of the lists usingmy_array=numpy.array(listofrandomizedconditions) my_array2=numpy.array(inputsuser) my_arra…

Retrieving information from dictionary

Im having hard time trying to read my dictionary variable. Python keeps throwing the following error:TypeError: string indices must be integersThis is a sample that should give you an idea of what my p…

Python WMI Hyper-v GetSummaryInformation result

Im trying to retrieve information from all the available VMs on a Hyper-V Server. The problem is that when I ask for the summary information, i get a list of useless COMObjects.I cant find a way of get…