Radar plot labels - python

I have fairly basic Python knowledge but I am trying to use it to plot a radar graph. I have done this before but now my script is causing an issue.
I don't need any data to demonstrate so I won't add it, my script draws a radar plot, and plots the data but when I add variable labels for some reason it zooms in on one quadrant of the radar plot.
fig = plt.figure()
plt.clf()
ax = fig.add_subplot(1, 1, 1, projection='radar')
ax.set_varlabels(labels)
Any ideas why and how to fix this, it used to work so I think there must have been an update and maybe I need a different command? I am using Python 3.6.4 via Anaconda.

Related

How to make plots customizable in python

I have two issues with my python plot that would be grateful if anyone could help me with:
1- I wonder if it is possible in python to have the option for the plots after display to add horizontal or vertical lines, so that these new lines could be added, moved or deleted without the need to run the code again.
to say it more clearly, I am looking for additional features that adding them does not need to change the code and they only enable me to manually draw on the already plotted image.
2- I want to plot a very large image in the real size, So that I need to add the horizontal and vertical slide bars to be able to scroll up/down or left/right in the plot?
I need to combine these two ability for my project, can someone help me with that?
1- You can't physically draw on it, but you can make a plot in matplotlib interactive as follows:
import matplotlib.pyplot as plt
plt.ion() # turns on interactive mode
fig = plt.figure()
ax = fig.add_subplot()
plt.ylim(-10, 10)
plt.xlim(0, 10)
while True:
plt.axhline(float(input("number")))
fig.canvas.draw()
fig.canvas.flush_events() # draws
This program allows you to create horizontal lines based on user input.
I think you can solve 2 with tkinter, but that would be pretty difficult. There might also an easier way. See this stack overflow question for an example of an interactive plot in tkinter. I believe this plot can be made bigger and scrollable, but I am not sure.

How can I plot figures from pandas series in different windows?

I am new in python and I create pandas series in a for-loop. Each time I want to plot the series in a figure. I use ax = series.plot(title = str(i)+'.jpg') but all figures are plotted in same window. How can I plot them in different windows?
If you are using matplotlib, use
plt.figure()
for every new figure you want to plot.
You then show all figures with
plt.show()
also, you should check out what subplots does.

How to send multiple plots generated by matplotlib to a pptx without any overlapping?

I am working on a project where I am generating hundreds of plots using the matplotlib module in Python. I want to put these plots in a pptx using the python-pptx module, let's say four plots on a slide without storing these plots on the local disk.
To overcome the storing problem I am using the BytesIO python module, which stores the plots inside the buffer, and then send these plots to the pptx.
The major issue that I am facing is the overlapping of the plots.
Question is how to send these plots serially to pptx so that we can avoid the overlapping?
Screenshot of pptx generated
I have added a screenshot of the pptx, where I am trying to add the two plots
Plot 1 (Age vs Name),
Plot 2 (Height vs Name),
but if you see the Plot 2 the data of plot 1 and plot 2 are getting overlapped. I want to avoid this overlapping.
You need to clear the axes between each plot, there are several ways to do that:
plt.clf(): clears the current figure
plt.cla(): clears the current axes
So instead of e.g.
plt.scatter(x, y1)
# save first plot
plt.scatter(x, y2)
# save second plot
You do
plt.scatter(x, y1)
# save first plot
plt.clf()
plt.scatter(x, y2)
# save second plot
And the two scatter plots will be drawn separately. This is probably the most 'blunt' way to approach this, but it should work fairly well. It is by no means the best way to do it for any specific case.
The figure is also cleared when plt.show() is called - but I expect that is undesirable in this case.

multiple graph (not subplot) using python and matplotlib

I would like to plot two or more graphs at once using python and matplotlib. I do not want to use subplot since it is actually two or more plots on the same drawing paper.
Is there any way to do it?
You can use multiple figures and plot some data in each of them. The easiest way of doing so is to call plt.figure() and use the pyplot statemachine.
import matplotlib.pyplot as plt
plt.figure() # creates a figure
plt.plot([1,2,3])
plt.figure() # creates a new figure
plt.plot([3,2,1])
plt.show() # opens a window for each of the figures
If for whatever reason after creating a second figure you want to plot to the first one, you need to 'activate' it via
plt.figure(1)
plt.plot([2,3,1]) # this is plotted to the first figure.
(Figure numbers start at 1)

Empty python plot

I'm running a script remotely on a cluster to generate a scatter plot. I wish to save the plot, but I don't want the plot to be display or a window to come up (as when you execute plt.show() ).
My saved plots are always empty. This is the code that I'm using (below). Any tips would be very helpful. Thanks!
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([-1,maxX+1])
ax.set_ylim([0,maxY+1])
ax.set_xlabel('Comparison number (n)', fontsize=18, fontweight='bold')
ax.set_ylabel('Normalized cross correlation score', fontsize=18, fontweight='bold')
ax.scatter(xaxis,yaxis)
plt.savefig('testfig.png')
In order to use avoid showing plot windows (i.e. to do off-screen rendering) you probably want to use a different matplotlib backend.
Before any matplotlib import statements, add
import matplotlib
matplotlib.use('Agg')
and subsequent calls to matplotlib will not show any plot windows.
If your plot file shows an empty axis, then the problem lies in the plotting arguments as calling plot with empty arguments creates an empty axis.

Categories