![]() In Matplotlib, but we'll get to those in a follow-up post. There are many other cool things you can do with pie (and donut) charts Hopefully that helps get you started creating pie charts in Matplotlib. See icon in the lower right corner in the screen shot: In the plot tools editor you can select the figure objects and change their properties. set_title ( 'Sport Popularity', fontsize = 18 ) plt. SSB, one way would be to use the plot tools. # if texts.get_text() = 'Lacrosse': # t_facecolor('dodgerblue') texts. explode = ( 0, 0, 0, 0.1 )) for i, patch in enumerate ( patches ): # You could also do something like this if you want to assign colors # by some rule or by value. pie ( x, labels = labels, autopct = ' %.1f%% ', wedgeprops =, startangle = 90, colors = colors, # "Explode" the Lacrosse wedge to highlight it. colors = 'dodgerblue' # You could also just manually assign colors very easily. linspace ( 0.45, 0.85, len ( x )))) # Swap in a bright blue for the Lacrosse color. This function has multiple arguments to configure the final plot: add a title, change axes labels, customize colors, or change line types, among others. get_cmap ( 'Greys' ) colors = list ( cmap ( np. subplots ( figsize = ( 6, 6 )) # Get four different grey colors. Of x that gives labels for each pie wedge.įor our example, let's say we want to show which sports are most popularĪt a given school by looking at the number of kids that play each. The labels argument should be an iterable of the same length and order The oneĬaveat here is that if the sum(x) < 1, the wedges won't automaticallyįill in the full pie. ![]() Matter Matplotlib will convert them to percentages regardless. They can be givenĪs decimals (percentages of total) or raw values, it doesn't really The values that will make up the wedges of the pie. The pie method takes an x parameter as its first argument, which is We'll use the former in ourĮxamples but any of these could be coded up as the latter instead. The axes Matplotlib object has a baked in pie method,Īs does the higher level pyplot library. So we'll go over how to code them up in Matplotlib, which Pie charts can be useful when utilized in the right context with the Pie charts don't have the best reputation in the visualization community,īut there are times when you want one anyway. Matplotlib beginner pie chart Basic Pie Chart in Matplotlib
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |