I almost completed my project but need some help. Let me summarize what I have already done. I exported a CSV file from ESXI, and using Python, I make several calculations and created a pie chart of these values. Here I have one result for calculation and the pie chart. Currently, I want to write these results to CSV simultaneously. How can I do that? As you know, pandas only display pie charts on different windows. I want to save that chart on CSV.
A pie chart is just a type of data visualization. I guess you are already using a dataframe to display this using plt.show().if you want to save that chart,
you could combine data,labels,colors to dataframe and save it as a csv. In order to save as csv: df.to_csv(file_name, sep='\t')
Related
I want to create a pivot chart plot using python and below is the data format(csv file)
below is the pivot chart plot using excel:
The code I used to generate pivot chart:
expect to see the same result as excel plot
As you can see from the figure created from python is not what I expected.
Any solutions for this problem?
Thank you very much!
I have a datframe with metric and grouping variables. I want to group the data by several grouping variables, do subplot and then export it to pdf. Right now I have a function which does subplots and returns it to another function. Then that function uses PdfPages to save the subplots to a pdf. However, the issue is that when number of subplots are way too many (like 200), it throws an error:-image size of 1296*96220 pixels is too large. I believe this is happening because my current codes are setup in such a way that it saved all the subplots to a single pdf page, making it a very large page. But then, that can go upto a limit, and since 200 charts are too many, I get this error. Because I have tried with 45 charts and it works. Note that data is in pandas dataframe and charting is done using matplotlib
Following is a rough idea of the code:
the first code takes in a dataframe, does a group by (can be multiple group by parameters) and then produces subplot. Imagine I have two groupby variables- A and B. so when i do subplot with the following code, I am expecting 20*15=300 subplots
grouped=df.groupby(grouping_vars)
fig,axs=plt.subplots( "some parameters")
fig.tight_layout
targets=zip(grouped.groups.keys(),axs.flatten())
for i,(key,ax) in enumerate(targets):
ax.plot("some parameters to plot based on group")
ax.set_title(key)
list_to_be_returned=[fig,plt]
return list_to_be_returned
Now, I use the following fucntion to save it to a pdf file
pp=Pdfpages(file_name)
pp.savefig(list_to_be_returned[0], bbox_inches='tight')
pp.close()
Now, what it does is puts all the subplots in a single large pdf page. I tried with 45 charts, and was successful. I am trying with 200 charts, and its throwing an error. Is there a way to instruct it to save maximum number of charts it can, on a single page, and then move on to next page once required.
I have 13 different saved CSV files in a folder and each file contains just one column of data (i previously saved these separately from a larger dataset using python having calculated what I needed to), I would like to plot each of these files as 13 different boxplots on the same plot.
I am quite new to python and I'm familiar with matplotlib, so far I know how to plot each of these files individually but of course, I would like them to be plotted next to each other so I can better compare and visualise my data.
here are two of my plots:
usingplt.boxplot(af,meanline=True,showmeans=True)
boxplot1
boxplot2
this is how I named/saved my files (just 2 of them here)
af=numpy.loadtxt(fname='af_river.csv.')
am=numpy.loadtxt(fname='am_river.csv.')
but I don't know where to go from here, do I/is there a way to create a loop which goes through each of these files separately and plots them next to each other?
Try this
plt.boxplot([af,am],meanline=True,showmeans=True)
This will plot all the files in the same plot
I'm trying to create a some of a complex chart using XlsxWriter, thus I need to add some data labels to my series. The problem is that the data labels I need are different from the series value.
Within Excel is something simple to do:
1) right click format data labels
2) label contains: values from cells
3) I then select the cells I want and it creates the data labels
If there is any way to do this, thanks in advance.
This feature isn't supported since it wasn't part of the original Excel 2007 file format.
There is a feature request for this: XlsxWriter/feature_request/343.
I'm using ReportLab for generating reports in PDF. I'm able to get a pdf havinf only textual content in it, but I want to represent the information in the form of a pie chart.
Here is the information that I want to represent on the pie chart.
[[New Delhi,110kWh],[Bangalore,200kWh]
ie a pir should have regions of New Delhi and Bangalore with their respective values in percentage.
How can I bring a pie chart into the PDF for generation of reports.
You can use matplotlib to generate a pie chart. See the example here.
Save the chart as a image file and place it in your PDF.
you can use this tutorial for creating pie-chart using ReportLab : http://www.reportlab.com/snippets/2/
For other types of scientific or data visualizations matplotlib is also good.