matplotlib

Creating a grouped sorted bar plot using pandas

◇◆丶佛笑我妖孽 提交于 2021-02-11 09:39:45
问题 I have been trying to create a grouped sorted bar plot such as this one http://chrisalbon.com/python/matplotlib_grouped_bar_plot.html from a DataFrame created from dict by doing: food = {'Apples as fruit': 4.68, 'Berries': 7.71, 'Butter': 12.73, 'Cheese': 4.11, 'Dairy, Other': 4.97} dframe = pd.DataFrame([food]) dframe.plot(kind='bar') Apples as fruit Berries Butter Cheese Dairy, Other 0 4.68 7.71 12.73 4.11 4.97 The first group should have Apples and Berries and the second should have Butter

Python - dual y axis chart, align zero

爷,独闯天下 提交于 2021-02-11 09:18:10
问题 I'm trying to create a horizontal bar chart, with dual x axes. The 2 axes are very different in scale, 1 set goes from something like -5 to 15 (positive and negative value), the other set is more like 100 to 500 (all positive values). When I plot this, I'd like to align the 2 axes so zero shows at the same position, and only the negative values are to the left of this. Currently the set with all positive values starts at the far left, and the set with positive and negative starts in the

Python - dual y axis chart, align zero

ぐ巨炮叔叔 提交于 2021-02-11 09:17:07
问题 I'm trying to create a horizontal bar chart, with dual x axes. The 2 axes are very different in scale, 1 set goes from something like -5 to 15 (positive and negative value), the other set is more like 100 to 500 (all positive values). When I plot this, I'd like to align the 2 axes so zero shows at the same position, and only the negative values are to the left of this. Currently the set with all positive values starts at the far left, and the set with positive and negative starts in the

Seaborn : linear regression on top of a boxplot

自作多情 提交于 2021-02-11 08:46:19
问题 With seaborn, how I can use sns.boxplot and sns.lmplot to obtain a boxplot with a regression line from the same data ? This does not work : tips = sns.load_dataset("tips") ax = sns.boxplot(x="size", y="tip", data=df) ax = sns.lmplot(x="size", y="tip", data=tips, x_estimator=np.mean); 回答1: You could try the following: tips = sns.load_dataset("tips") ax = sns.boxplot(x="size", y="tip", data=df) ax = sns.regplot(x="size", y="tip", data=tips); plt.show() Instead of using lmplot you can use

How to display several matplotlib plots in one django template page

喜夏-厌秋 提交于 2021-02-11 07:46:33
问题 I am working on a small app with Django framework. In one of my templates, I have a for loop in which I call an image of a matplotlib plot. But Django is mixing all of my data : some plots charge well, others completly crash and some of them mix the data of two plots. When I charge only one plot, it works fine but the problem occurs randomly when I have two or more plots on the same page. I understand that the problem is due to the simultaneous creation of all plots. Matplotlib is not

How to display several matplotlib plots in one django template page

北慕城南 提交于 2021-02-11 07:46:11
问题 I am working on a small app with Django framework. In one of my templates, I have a for loop in which I call an image of a matplotlib plot. But Django is mixing all of my data : some plots charge well, others completly crash and some of them mix the data of two plots. When I charge only one plot, it works fine but the problem occurs randomly when I have two or more plots on the same page. I understand that the problem is due to the simultaneous creation of all plots. Matplotlib is not

matplotlib scatter plot with xyz axis lines through origin (0,0,0) and axis project lines to each point

邮差的信 提交于 2021-02-11 07:14:38
问题 I always have this problem when plotting with matplotlib... they have no concept of drawing the axis lines on the plot, in this case, I specifically want xyz axis lines drawn on a scatter plot so that it looks like the attached photo, including the project lines from the point back to the axis. ploting a point with explicit axis lines through origin instead this is what i get: # from jupyter notebook %matplotlib from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import

Matplotlib: different scale on negative side of the axis

人盡茶涼 提交于 2021-02-11 06:53:23
问题 Background I am trying to show three variables on a single plot. I have connected the three points using lines of different colours based on some other variables. This is shown here Problem What I want to do is to have a different scale on the negative x-axis. This would help me in providing positive x_ticks, different axis label and also clear and uncluttered representation of the lines on left side of the image Question How to have a different positive x-axis starting from 0 towards

Error bars in matplotlib display over other curves

时光总嘲笑我的痴心妄想 提交于 2021-02-11 06:52:27
问题 I have a plot in which some data is represented by a scatter plot with error bars and I want to fit a curve to it. However, no matter where in the code I plot the curve, the error bars float on top of it. I want the fitted curves to display in front of the error bars because otherwise I can't see it. Here is a simple example of the issue: import numpy as np import matplotlib.pyplot as plt import matplotlib x = np.arange(1,10) r = np.random.random(x.size) fig1, ax = plt.subplots() ln1 = ax

How to highlight a plotline chart with vertical color bar for specific weekdays (saturday and sunday)? [duplicate]

冷暖自知 提交于 2021-02-11 06:52:11
问题 This question already has answers here : how to highlight weekends for time series line plot in python (2 answers) Closed 3 days ago . i plotted a daily line plot for flights and i would like to highlight all the saturdays and sundays. I'm trying to do it with axvspan but i'm struggling with the use of it? Any suggestions on how can this be coded? (flights.loc[flights['date'].dt.month.between(1, 2), 'date'] .dt.to_period('D') .value_counts() .sort_index() .plot(kind="line",figsize=(12,6)) )