Matplotlib figure not working [duplicate] - python

This question already has answers here:
How do I change the size of figures drawn with Matplotlib?
(14 answers)
Closed 5 years ago.
I have all of my graphs working, so now I am trying to scale my plots down to a relatively small size (3x3in). I added the figure command and the graph goes blank. Right size, just blank. I'm obviously missing something basic but it's beating me. When I comment it out, it shows fine ( if a bit big). When I include it, it blanks the image.
What am I doing incorrectly ?
plt.setp(line[lindex], linewidth=1.0)
plt.setp(line[lindex+1], linewidth=2.0)
plt.xlabel("Months")
plt.ylabel("Score")
plt.title(CurrAppName + "- by month")
plt.legend()
# plt.figure(figsize=(3,3))
plt.show()

If this is your whole code, just put the plt.figure(figsize=(3, 3)) as the first line. Here, declaring plt.figure(...) in the end means you are creating a whole new plot after you've drawn into the last one. You don't want that.

Related

Why will my y value not show up on my graph? [duplicate]

This question already has answers here:
How to plot a single point in matplotlib
(2 answers)
Closed yesterday.
I actually cannot seem to figure out why my y value will not show up on the graph. This is a much simpler graph than ones that I have done in the past, yet I seem to be struggling with this. What could be the reason that the y value won't show up?
When I change the value of y, the limits of the graph change accordingly but the value is still missing.
replace ax.plot(0, y) with replace ax.plot(0, y, marker='o')
Since (0, 2.5) is an infinitely small point, you need to give it a marker so it's visible.

How to create scrollbar in a plot? [duplicate]

This question already has answers here:
How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?
(2 answers)
Closed 3 years ago.
I have a lot of data series (> 1000 bars). For this reason the plot is scaled very small. Do you know how I can activate a scrollbar in the plt.barh-chart with python? If I can set a fixed height of the bars then I can scroll through the > 1000 bars. Perhaps you have another solution for me?
You have to set position for scrollbar with respect to image size.
Kindly refer a below URL:
Scrollable Bar graph matplotlib
Could you provide a reproducible example? Other than that I can just give you plain advice. First of all, ask you whether you are really in need of Youtube/Netflix/etc. 1-10. Because it makes the chart very confusing. I came across the same problem some time ago too and I figured that the Gantt Chart from Plotly, particularly for Python, is a really good solution to make it clearer.
As for your original question:
fig= plt.figure(figsize=(6,3))

Remove dashes from grid [duplicate]

This question already has an answer here:
Remove the x-axis ticks while keeping the grids (matplotlib) [duplicate]
(1 answer)
Closed 5 years ago.
If I run this code
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_tick_params(length=0,labelsize=0)
ax.grid(True)
I get the following:
The xaxis ticks and labels don't show (as expected), but some dashes appear on the bottom of the plot (the first three of which I have circled in red).
How can I remove them? I have looked at the documentation for grids, but can't find anything.
An answer which teaches me how I could have figured out how to do this by looking at the documentation would be particularly useful.
What you see are the ticklabels, which have size 0. Even zero sized ticks appear as a single dot because of antigraining.
You probably want to set the label off completely
ax.xaxis.set_tick_params(length=0,labelbottom=False)
You find out about this by looking at the available arguments in the documentation.

matplotlib.figure.suptitle(), what does 'sup' stand for? [duplicate]

This question already has an answer here:
In matplotlib, what's the difference between title() and suptitle()?
(1 answer)
Closed 5 years ago.
I understand that matplotlib.figure.suptitle() adds a title to a figure.
But what does the "sup" stand for?
It is an abbreviation indicating a "super" title. It is a title which appears at the top of the figure, whereas a normal title only appears above a particular axes. If you only have one axes object, then there's unlikely an appreciable difference, but the difference happens when you have multiple subplots on the same figure and you would like a title at the top of the figure not on each of the axes objects.

Using Matplotlib to add text along with a plot in a pdf file [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a way of drawing a caption box in matplotlib
I am trying to add a text description of a graph that I draw with matplotlib. I was wondering if there was a way to add a small description that is not in the frame of the graph (ie. either below it or above it).
I saw this link add text to existing pdf using python, but I would like to use matplotlib to do so. If there is no way to do this outright, is there another way (such as creating another figure, but instead of plotting coordinates, writing text in the area)?
I also noticed there is figtext(x, y, s, fontdict=None, **kwargs), but this adds text at certain coordinates.
#Jim, if I understand your question correctly, you're looking for a text area to use as a caption or description below a figure in matplotlib.
If so, you may find your answer through this duplicate question.

Categories