In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the use of the strongest Python visual drawing library Plotly". In the daily operation, I believe that many people have doubts about the use of the strongest Python visual drawing library Plotly. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what is the use of the strongest Python visual drawing library Plotly?" Next, please follow the editor to study!
Overview of Plotly
Plotly's Python package is an open source code base based on plot.js, which is based on d3.js. What we actually use is a library that encapsulates plotly, called cufflinks, which makes it easier for you to use plotly and Pandas tables to work together.
_ * Note: _ _ Plotly itself is a visualization technology company with several different products and open source toolsets. The Python library of _ Plotly is free to use. You can create an unlimited number of charts in offline mode, while online mode can only generate and share 25 charts because it uses Plotly's sharing service.
All the visual diagrams in this article are done in Jupyter Notebook using the plotly + cufflinks library in offline mode. After completing the installation using pip install cufflinks plotly, you can complete the import in Jupyter with the following code:
Univariate distribution: bar chart and box chart
Univariate analysis chart is often the standard practice at the beginning of data analysis, and bar chart is basically one of the necessary charts for univariate distribution analysis (although it has some shortcomings).
Take the total number of likes on blog posts as an example (see Github: https://github.com/WillKoehrsen/Data-Analysis/tree/master/medium for the original data), and make a simple interactive bar chart:
(df in the code is a standard Pandas dataframe object)
(interactive bar chart created using plotly+cufflinks)
For students who are used to matplotlib, you only need to type one more letter (change .plot to .iplot) to get a more beautiful-looking interactive chart! Clicking on the elements on the picture shows details, zooms at will, and has great features such as highlighting and filtering certain parts (as we'll talk about later).
If you want to draw a stacked bar chart, that's all you need:
Simply process the pandas data table and generate a bar chart:
As shown above, we can integrate the capabilities of plotly + cufflinks and pandas. For example, we can first use .pivot () for PivotTable analysis, and then generate a bar chart.
For example, count the number of new fans brought by each article in different publishing channels:
The advantage of interactive charts is that we can explore data and break down molecular items for analysis at will. Box charts can provide a lot of information, but if you don't see the specific values, you're likely to miss a lot of them!
Scatter plot
Scatter plots are at the core of most analyses, allowing us to see how a variable changes over time, or the relationship between two (or more) variables.
Time series analysis
In the real world, a considerable part of the data has time elements. Fortunately, plotly + cufflinks is born with the ability to support visual analysis of time series.
Taking the data of the article I published on the Towards Data Science website as an example, let's build a dataset indexed by the release time and see how the popularity of the article changes:
In the figure above, we accomplish several things with a single line of code:
Automatically generate beautiful X axis of time series
Add the second Y axis because the ranges of the two variables are not the same
Place the title of the article in the label displayed during mouse hover
To display more data, we can easily add text comments:
(scatter plot with text notes)
In the following code, we color a bivariate scatter graph according to the third classification variable:
Next we're going to play with something complicated: logarithmic axes. We do this by specifying the layout parameter of the plotly (see the official document https://plot.ly/python/reference/ for different layouts), and we bind the point size (size parameter) to a numeric variable read_ratio (reading ratio). The larger the number, the larger the bubble size.
If you want to be more complex (see the Github source code for details), we can even insert four variables into a picture! (however, it is not recommended that you really do so.)
As before, we can combine pandas and plotly+cufflinks to implement many useful charts:
It is recommended that you check the official documentation, or the source code, for more examples and function examples. With a simple line or two of code, you can add useful elements such as text notes, guides, and best fit lines to your chart, while maintaining the original interactive functions.
Advanced drawing function
Next, we will introduce several special charts in detail, which you may not use very often, but I guarantee that as long as you use them well, you will be impressed. We need to use plotly's figure_factory module to generate a great chart with just one line of code!
Scatter plot matrix
If we want to explore the relationships between many different variables, the scatter matrix (also known as SPLOM) is a great choice:
Even such complex graphics are fully interactive, allowing us to explore the data in more detail.
Relationship heat map
In order to reflect the relationship between multiple numerical variables, we can calculate their correlation and then visualize them in the form of annotated heat maps:
Custom theme
In addition to the endless variety of charts, Cufflinks also provides many different coloring themes, making it easy for you to switch between different chart styles. The following two pictures are the "Space" theme and the "ggplot" theme:
In addition, there are 3D charts (surfaces and bubbles):
For users interested in research, it is not difficult to make a pie chart:
Edit in Plotly Chart Workshop (Plotly Chart Studio)
When you generate these charts in Jupyter Notebook, you will find a small link in the lower right corner of the chart that reads "Export to plot.ly (publish to plot.ly)". If you click on this link, you will jump to a "chart workshop" (https://plot.ly/create/).
Here, you can further modify and polish your chart before the final presentation. You can add annotations, choose the colors of certain elements, sort everything out, and produce a great chart. After that, you can post it on the web and generate a link for others to refer to.
The following two pictures were made in the graphic workshop:
After talking so much, are you tired of reading? However, we have not exhausted all the functions of this library. Limited to space, there are some better charts and examples, so please visit the official documents of plotly and cufflinks to check them one by one.
At this point, the study on "what is the use of the strongest Python visual drawing library Plotly" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.