In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to draw scatter plots with Python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to draw scatter plots with Python"!
You think the scatterplot looks like this:
In fact, scatter plots can also grow like this:
bubble chart
Big Wild Goose Flying South
Does it look tall and beautiful? Let's take you to learn how to draw beautiful scatter plots with pyecharts.
1. The most basic scatterplot
from pyecharts import options as opts from pyecharts.charts import Scatter x=['January',' February','March',' April','May',' June','July',' August','September'] y=[8,5,3,4,8,2,2,5,1] c = ( Scatter() .add_xaxis(x) .add_yaxis("", y) .set_global_opts(title_opts=opts.TitleOpts(title="base") ))c.render_notebook()
This is the most basic scatterplot, just input horizontal and vertical two lists can output graphics
II. Scatter plot showing dividing lines
from pyecharts import options as opts from pyecharts.charts import Scatter x=['January',' February','March',' April','May',' June','July',' August','September'] y=[8,5,3,4,8,2,2,5,1] c = ( Scatter() .add_xaxis(x) .add_yaxis("", y) .set_global_opts( title_opts=opts.TitleOpts(title="base"), xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)), yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)) ))c.render_notebook()
You can set horizontal and vertical dividing lines according to your own needs
III. Setting Multidimensional Data
from pyecharts import options as opts from pyecharts.charts import Scatter from pyecharts.commons.utils import JsCode x=['January',' February','March',' April','May',' June','July',' August','September'] y=[8,5,3,4,8,2,2,5,1] c = ( Scatter() .add_xaxis(x) .add_yaxis("", y, label_opts=opts.LabelOpts( formatter=JsCode( "function(params){return params.value[1] +' : '+ params.name;}" ) ),) .set_global_opts( title_opts=opts.TitleOpts(title="Scatter-Multidimensional Data"), visualmap_opts=opts.VisualMapOpts( type_="color", max_=8, dimension=1 ), ))c.render_notebook()
Mainly through the insertion of js code to achieve
IV. Bubble Chart
By segmenting the dot plot, setting different colors, and setting the radius of the dots to change with the data, the scatter plot becomes a bubble plot.
from pyecharts import options as opts from pyecharts.charts import Scatter x=['January',' February','March',' April','May',' June','July',' August','September'] y=[8,5,3,4,8,2,2,5,1] c = ( Scatter() .add_xaxis(x) .add_yaxis("", y) .set_global_opts( title_opts=opts.TitleOpts(title="Bubble Plot"), visualmap_opts=opts.VisualMapOpts( range_opacity=0.45, type_="size", max_=10, is_piecewise=True, dimension=0, pieces=[ {"lte": 2, "color": "green"}, {"gt": 2, "lte": 4, "color": "red"}, {"gt": 4, "lte": 6, "color": "yellow"}, {"gt": 6, "lte": 8, "color": "red"}, {"gt": 8, "color": "green"}, ], pos_right=0, pos_bottom=100) ))c.render_notebook()
Parameter introduction:
range_opacity: set transparency type: size, use shape size to represent data size
is_piecewise: whether to segment pieces: specific segmentation range
V. Set the shape, size and color of scattered points
By changing the shape, size, and color of the dots, you can make the dots look like geese flying south.
from pyecharts import options as opts from pyecharts.charts import Scatter x=['January',' February','March',' April','May',' June','July',' August','September'] y=[8,5,3,4,8,2,2,5,1] c = ( Scatter() .add_xaxis(x) .add_yaxis(series_name="", y_axis=y, symbol='arrow', symbol_size=[40,20], symbol_rotate=-45) .set_global_opts( title_opts=opts.TitleOpts(title="base"), visualmap_opts=opts.VisualMapOpts(max_=10), ))c.render_notebook() Key parameters: symbol: set shape symbol_size: set shape size ymbol_rotate: set shape angle
Key parameters:
symbol: set shape
symbol_size: Set the shape size
ymbol_rotate: Set the shape angle
At this point, I believe everyone has a deeper understanding of "how to draw scatter plots with Python," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.