Plotly and the Plotly Figure
1. Plotly and the Plotly Figure
Welcome to an Introduction to Data Visualization with Plotly (in Python!)2. What is Plotly?
So what is Plotly exactly? Plotly is actually a JavaScript library. Don't worry - you don't need to know JavaScript for this course! We will use a Python wrapper library. That is, we will write code in Python, which will produce JavaScript code.3. Why Plotly?
So why Plotly? Yet another data visualization library? Plotly has a number of advantages over other Python-based data visualization libraries. It's fast and easy to use. The plotly express module allows for very low-effort, professional graphs to be produced. However, there are also a lot of customization options if you wish. Best of all, interactivity comes built-in, including hover effects!4. Creating Plotly Figures
You can build Plotly charts in two main ways. plotly express is the simplest to create basic, common plot types quickly. You can also make more customized and advanced plots with plotly graph_objects. In this course we will spend most of our time using plotly express.5. The importance of documentation
Plotly is highly customizable, with many more options than we will cover in this course. Therefore, the documentation is essential. There's a great interactive documentation site packed with examples. Each plot type also has a detailed reference page listing all available arguments. For scatter plots, for example, we can find a guide and a technical reference for the underlying object.6. Creating our Figure
Let's see how a basic figure could be created using plotly express. We import the library as p x. We define days of the week and temperature values. We call p x dot bar to create a bar chart, setting the axes and a title. Finally, we display it using a show method.7. Our Figure revealed
With just a few lines of code, we've created a fully interactive bar chart!8. The Plotly Figure
Now, let's get into the technical side of things. A Plotly figure has three main components. Layout is a dictionary of attributes that control the look and style of the figure. There is one layout element per figure. The data element is a list of dictionaries that sets up the type of graph and the data to display. The combination of data and type is a trace. You may have multiple traces per plot. There is also a frames element we won't use in this course.9. Inside a Plotly Figure
We can see inside our figure by just printing out the object. Have a look at the code here. There is a data element with a type of bar, and some X and Y data. There is also a title with some text discussing temperatures on weekdays.10. Plotly's instant interactivity
Creating any plot gives some instant interactivity. Plotly graphs have hover-over pop-ups. On the previous slide, I hovered over several days. There is also a bar of extra interactive buttons. These allow you to download the plot, select or zoom in on it, and view it using various other options.11. Let's practice!
Let's create and explore your first Plotly chart!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.