This question already has an answer here:
Show categorical x-axis values when making line plot from pandas Series in matplotlib
(1 answer)
Closed 4 years ago.
I have imported an Excel file and want to plot a 2D graph by using data from that file.
I have used matplotlib to plot graph by using
df.plot("Col1","Col2") but its is not showing X-labels in the graph which should be text(Col1)
What changes should I apply to Code()?
According to pandas docs your code is correct. Perhaps you can try another method of showing the x-label in order to see where the problem comes from. You can try the following
ax = df.plot() # retrieve the matplotlib Axes object
ax.xlabel("Col1") # set the x-label
ax.ylabel("Col2") # set the y-label
See this docpage
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlabel.html
Related
This question already has answers here:
Python Pylab scatter plot error bars (the error on each point is unique)
(2 answers)
Error Bars with Seaborn and Stripplot
(1 answer)
Closed 3 months ago.
I am trying to generate a horizontal chart for the dataset I have. I am trying a get a chart that looks like this using Python.
This is how my dataset looks like:
How do I get this dataset to look like a straight horizontal line with a dot representing the average?
When I use plt.plot, I get something like this:
This question already has answers here:
Move seaborn plot legend to a different position
(8 answers)
Closed 1 year ago.
Whenever I try to use the hue feature in seaborn it works fine if the column used in Hue has lesser values. But in case of larger number of values it covers/shadows the main plot. Is there anyway to keep/position the hue column value details not on the top of the main plot.
I believe easiest solution is just to enlarge fig size, as plot will take smaller relative size.
Seaborn's doesn't handle well with legends in my opinion. You can edit legend using matplotlib function: matplotlib's legend guide
Some possible solutions:
Move legend outside: Move legend outside figure in seaborn tsplot
resizing the plot: How to move the legend in Seaborn FacetGrid outside of the plot?
smaller text in legend(see first answer): How to put the legend out of the plot
This question already has answers here:
matplotlib: can I create AxesSubplot objects, then add them to a Figure instance?
(5 answers)
pyplot - copy an axes content and show it in a new figure
(2 answers)
Closed 3 years ago.
When I want to make several subplots in a figure I can do, for example, the following
figA=plt.figure('figA',figsize=(30,25))
(ax2,ax1) = figA.subplots(2,1, gridspec_kw={'height_ratios':[1,15]})
And I can then make the plot using ax2.plot(data2) and ax1.plot(data1)
Then I might want to do another separate figure:
figB=plt.figure('figB',figsize=(30,25))
(ax2B,ax1B) = figB.subplots(2,1, gridspec_kw={'height_ratios':[1,15]})
However, I need the exact same top panel as in the previous figure.
What should I do if I want ax2B to always be identical to ax2, no matter what changes I make to the subplot?
In other words, I would like to define a subplot and apply it to several figures, rather than defining it inside a specific figure.
If for example in the top panel I want a straight line f(x)=x, I will do
import numpy as np
X=np.linspace(0.,10.,10)
ax2.plot(X,X)
ax2B.plot(X,X)
but I do not want to define the exact same plot twice. I want to just define a subplot once and for all and then call it in a new figure when I need it.
This question already has answers here:
How to adjust padding with cutoff or overlapping labels
(8 answers)
Closed 4 years ago.
So I'm using yellowbrick in Python, which is basically matplotlib and scikit-learn combined, to visualize some data.
My chart looks like this:
The labels get cut off. What I want to do is to adjust the figure so the labels on the right don't get cut off. I tried
plt.rcParams['figure.figsize'] = (10, 5)
plt.rcParams['font.size'] = 12
but when I rendered the figure, it's still cut off. Even when I save it as a png file it's still cut off. What am I missing here?
tight_layout method should solve your problem.
Generally you can use it with:
fig.tight_layout() # if fig is your figure handle
or
plt.tight_layout() # if stated within the context of your figure
This line of code should be added after the last plotting statement just before rendering the figure.
If this does not work, please post a fully working minimal code example, as described in mcve. Afterwards I'll be able to post a fully working solution for most, if not all, cases.
This question already has answers here:
How to remove gaps between subplots in matplotlib
(6 answers)
Closed 5 years ago.
I am attempting to plot a graph similar to the one attached below. The y-axis should be aligned and the x-axis scale and name should be same. Also, I want the dotted line as shown in the figure.
I tried combining two different graphs but that is certainly not a good way to solve this.
Sorry for the poor quality picture but the important points are mentioned.
Look into the matplotlib docs. I think you might be looking to use plt.subplots with the sharex argument.