My pandas data frame has two columns: category and duration. And
I use the following code to make a box plot of all data points.
import matplotlib.pyplot as plt
plt.boxplot(df.duration)
plt.show()
However, if I want one box fore each category, how do I modify the above code? Thanks!
In addition to Wen's answer, which is spot on, you might want to check out the seaborn library. It was made to do this kind of plot.
Seaborn is a Python visualization library based on matplotlib. It
provides a high-level interface for drawing attractive statistical
graphics.
Check the documentation for boxplots
Draw a box plot to show distributions with respect to categories.
sns.boxplot(data=df, x='category', y='duration')
We can do it with pandas
#df=pd.DataFrame({'category':list('aacde'),'duration':[1,3,2,3,4]}) sample data
df.assign(index=df.groupby('category').cumcount()).pivot('index','category','duration').plot(kind='box')
Related
Cartopy seems like a great tool for Geoscience, but it appears to lack a method for plotting vector data on a map together with their error ellipses. Is there a straightforward way to add error ellipses centered on the tips of vector data?
Cartopy inherits all its vector plotting functionality from matplotlib. Cartopy provides a way to project the vectors, but they are drawn by matplotlib. I haven't heard of a feature you describe in matplotlib, so I'm afraid the answer is probably no.
I am trying to use both seaborn and matplotlib defaults to create plots in an ipython notebook, each plot with it's own default mpl or sns style. I have followed the instructions outlined in this question, and this one, however they don't quite do what I need.
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16])
import seaborn as sns
plt.plot([1,2,3,4], [1,4,9,16])
sns.reset_orig()
plt.plot([1,2,3,4], [1,4,9,16])
The last plot saves without the grey border, however the size is still different than the original. And the inline display is not the same as the original. Ideally I would like to be able to set the style on a per plot basis. Does anyone have any suggestions on how to achieve this?
I don't know any way to describe this plot, but I need to do it preferably with matplotlib. If there is a name for this plot, I would love to know it.
It can be found on page 10 of this PLOS ONE paper (Figure 6): http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0093590
Basically, each section is made up of three plots. One scatter plot, and two histograms that show the density of points in each region, one for each axis.
Any help would be great. Thanks.
I want to create a contour plot with matlibplot and generate a shapefile from it so that I can use it in QGIS to display it.
Though it is possible to plot a map with matplotlib and then overlay with my contour plot, the choices of map sources are limited. It would be easier to export the contour plot in a shapefile and loaded in QGIS with a customized map.
Thanks!
There is a contour plugin available in QGIS, and it is based on the contouring functions of matplotlib. It's still a little bit buggy but hopefully that will be corrected in the future.
I am using matplotlib for visualisation. I need 3d visualisation and also the animations in my visualisation. I have searched about the 3d visualisation and animation in matplotlib but get nothing useful information. Is it possible or not to use matplotlib for 3d visuallisation and animations. What are the links that I can study about it ?
Animation and 3D plot are available on mplot3d library. Take a look at wire3d_animation and mayavi Animation.
Here is what I, probably most of people, use for python numpy plotting.
For 2D figure plotting, use matplotlib.
For 3D surface and volume plotting, use mayavi.
Both of them come with their own approaches of animating plots. Nevertheless, moviepy is a great alternative approach.