I have been trying to generate a code in python that automatically creates a graph from unknown amount of data point in an excel spread sheet.
The data in the excel sheet does not always have the same ending point so I need the code to automatically read how many data points are in the excel file and graph it automatically. It also has to be able to handle large numbers of data point like into the 4000's. And also find the average, max and min.
Sample of the excel data (I only need it to read the first two columns which will be the x and y)
Is there way to save a "Figure" in matplotlib to a file such that if you later wanted to modify the Figure, e.g. change data points, resize the figure, etc. you could load up the file in a new python script and do that?
Right now I save the majority of my plots as Pdfs, but that doesn't allow me to make edits later on. I have to go dig up my old source code and data files. I've lost track of the number of times I've lost the plot-generating code and have to essentially reproduce it all from scratch.
It would be nice if I could just save a plot as a self-contained data file, like Photoshop does with its .psd files, so that I can just load it up directly, type "object.plot()", and not have to worry about external dependencies. Does such a format exist, or if not is there any way I could achieve this?
There is a method of saving the plotted object called pickling. I don't have much experience with it but it should allow you to save the plot to a file using
fig = plt.figure
pl.dump(fig, file('file_name.pickle','w'))
and using
fig = pl.load(open('file_name.pickle','rb'))
fig.show()
to load the saved graph.
Matplotlib warns that, "Pickle files are not designed for long term storage, are unsupported when restoring a pickle saved in another matplotlib version". To be safe, I would just save the array containing the data to the plot to either a .csv or .txt file, and keep this file in a folder with the python file to plot the graph. This way you will always be able to plot your data (no matter the version of matplotlib you are using). You will also have the data and code in the same place, and you can easily read the data from the .csv or .txt file, save it to arrays, and graph it using
file = open("file_name.txt", "r")
if file.mode == 'r':
data = f.read().splitlines()
data_array1 = data[0].split(",")
data_array2 = data[1].split(",")
p, = plt.plot(data_array1, data_array2)
I also suggest uploading your python files along with your .csv or .txt files to Github.
If you would like to read more about pickling in matplotlib I suggest reading the two pages linked below.
(1) Pickle figures from matplotlib
and (2) https://matplotlib.org/3.1.3/users/prev_whats_new/whats_new_1.2.html#figures-are-picklable
I am reading an unstructured excel file(with lot of merged cells of no particular size) into pandas data frame and the content in merged cells is getting read into top left cell position in pandas and it fills the other cells with null values. Now there are many null values already present in the excel file and i want to find a way to specifically track the locations of cells with null values that were created after unmerging when read into pandas. I don't find any way in python that could do this thing. Could anyone guide me how to approach this problem?
I guess you use pandas.read_excel() to get data from Excel into the data frame?
Given the merged cells in the Excel sheet, I believe you will need to read the data yourself using one of the libraries listed on http://www.python-excel.org/ (I recommend openpyxl).
You can then control the excel-to-dataframe conversion yourself.
I have excel sheet which contains plotted graph. I want to save these plots as jpeg image file with python. I know how to read data from excel file with python, is there any way of reading these images and saving them as jpeg?
The excel looks like following.
How to extract data from plot data filter in paraview through python script?? I want to get data through python script by which paraview is drawing the graph.
If anyone know this answer please help
Thank you
Usually plots are made by plotting one data array versus another. You can often obtain that data directly from the filter/source that produced it and save it to a CSV file. To do this, select
You can save data from a filter as a CSV file by selecting the filter/source in the Pipeline Browser and choosing File -> Save Data. Choose the CSV File (*.csv) file type. Arrays in the filter/source output are written to different columns in the CSV file.