![]() We then update the layout with barmode="group" to turn it into a grouped bar chart. With the new array of dummy data, we now loop through each of the list of values in the array and add a bar chart to the figure. ![]() # create more dummy data vals_2 = np.ceil(100 * np.random.rand(5)).astype(int) vals_3 = np.ceil(100 * np.random.rand(5)).astype(int) vals_array = Let’s first make a couple more sets of dummy data so we can create our grouped and stacked bar charts. To do this, we can add multiple bar charts to our figure first, and then use fig.update_layout() to change the mode of the bar chart. If we wanted to compare the values of multiple groups with the same keys, we can either make a grouped or stacked bar chart. Modified Bar Chart - figure created by author Grouped and Stacked Bar Charts # plot data fig.add_trace( go.Bar(x=keys, y=vals) ) fig.update_layout(height=600, width=600) fig.show() To make it easier to see, we can also update the height and width of the figure in the layout. We now add the bar plot to our figure and show the result with the following lines of code. The first thing we need to do is create a figure using aph_objects: # import packages import aph_objects as go # create figure fig = go.Figure() Now we can plot each of these key-value pairs on a bar plot. We can do so using numpy as follows: # import packages import numpy as np # create dummy data vals = np.ceil(100 * np.random.rand(5)).astype(int) keys = Let’s start by creating some dummy data to plot in our bar chart. As we did in the my previous article on this topic, we will use aph_objects to build our figures from scratch. We will look at bar charts, histograms, scatter/bubble charts, and box plots. In this post, I will demonstrate some of the other basic plot options within plotly and how to set up paneled figures by utilizing subplots. Now that you have some background in using the plotly package (if you want a good introduction, you can read a previous article that I wrote), you may want to expand some of the plotting options that you have.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |