Latest Questions tagged Matplotlib

Browse all latest questions tagged Matplotlib

12
Votes
Published 31 Aug, 2022
Python - What does 'numpy.ndarray' object has no attribute 'barh' mean and how to rectify it?

I want to plot a 5 x 4 plots. The code for the same is below fig, axis = plt.subplots(5, 4,figsize=[25,10]) i = 0 for channel in np.unique(data_recent['channel_id']): for year in np.unique(data_r...

54
Votes
Published 28 Jun, 2022
Python - ValueError: Invalid RGBA argument: 'rgbkymc'

train_class = train_df['Class'].value_counts().sortlevel() my_colors = 'rgbkymc' #red, green, blue, black, etc. train_class.plot(kind='bar', color=my_colors) plt.grid() plt.show() I'm getting: Val...

58
Votes
Published 26 Aug, 2022
Python - Add plots directly to a document using python package docx

I am plotting some data and I want to automatically generate a report. I can save the plot and then add it to my document. However, I prefer to do it directly, without saving step. Going through the p...

49
Votes
Published 27 Aug, 2022
Python - How to set center color in heatmap

I want to plot a heatmap in seaborn. My code is following: plt.rcParams['font.size'] = 13 plt.rcParams['font.weight'] = 'bold' my_dpi=96 fig, ax = plt.subplots(figsize=(800/my_dpi, 600/my_dpi), dpi=m...

21
Votes
Published 01 May, 2022
Python - Plot feature importance with xgboost

When I plot the feature importance, I get this messy plot. I have more than 7000 variables. I understand the built-in function only selects the most important, although the final graph is unreadable....

17
Votes
Published 08 May, 2022
Python - Labeling boxplot in seaborn with median value

How can I label each boxplot in a seaborn plot with the median value? E.g. import seaborn as sns sns.set_style("whitegrid") tips = sns.load_dataset("tips") ax = sns.boxplot(x="day", y="total_bill",...

41
Votes
Published 29 Aug, 2022
Python - matplotlib bar chart with dates

I know about plot_date() but is there a bar_date() out there? The general method would be to use set_xticks and set_xticklabels, but I'd like something that can handle time scales from a few hours ou...

116
Votes
Published 27 Aug, 2022
Python - Matplotlib - add colorbar to a sequence of line plots

I have a sequence of line plots for two variables (x,y) for a number of different values of a variable z. I would normally add the line plots with legends like this: import matplotlib.pyplot as plt...

68
Votes
Published 27 Jun, 2022
Python - Python histogram with points and error bars

I want to plot a histogram with points and error bars. I do not want bar or step histograms. Is this possible? Google has not helped me, I hope you can. Also it should not be normalized. Thanks!

38
Votes
Published 23 Aug, 2022
Python - Matplotlib.animation: how to remove white margin

I try to generate a movie using the matplotlib movie writer. If I do that, I always get a white margin around the video. Has anyone an idea how to remove that margin? Adjusted example from http://ma...

38
Votes
Published 23 Aug, 2022
Python - Plotting profile hitstograms in python

I am trying to make a profile plot for two columns of a pandas.DataFrame. I would not expect this to be in pandas directly but it seems there is nothing in matplotlib either. I have searched around an...

34
Votes
Published 29 Aug, 2022
Python - smooth the path of line with python

I have a set of points, all together they create a track, where the sequence is crucial. I can plot the track using lines, how could I smooth it after or while new points are fetching? Track might loo...

22
Votes
Published 08 Aug, 2022
Python - custom scaling of wind rose python

I am trying to compare wind roses in python, but it is difficult because I cannot figure out how to make the same scale across all of the plots. Someone else asked the same question here Custom perce...

22
Votes
Published 06 May, 2022
Python - Image overlay in 3d plot using python

I have a 3d plot of lines generated by matplotlib. I want to overlay an image at a specific xy (or yz, xz) slice. How do I do that using python? Thanks. I have a simple 3d plot code as: fig = plt.fi...

11
Votes
Published 21 Aug, 2022
Python - setting a legend matching the colours in pyplot.scatter

Suppose my data is organized in the following way: x_values = [6.2, 3.6, 7.3, 3.2, 2.7] y_values = [1.5, 3.2, 5.4, 3.1, 2.8] colours = [1, 1, 0, 1, -1] labels = ["a", "a", "b", "a", "c"] I want to...