In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Python in how to draw a variety of line charts, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
1. Basic line chart import pyecharts.options as optsfrom pyecharts.charts import Linex= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Sunday'] y = [100200300400500400300] line= (Line () .set _ global_opts (tooltip_opts=opts.TooltipOpts (is_show=False), xaxis_opts=opts.AxisOpts (type_= "category")) Yaxis_opts=opts.AxisOpts (type_= "value", axistick_opts=opts.AxisTickOpts (is_show=True), splitline_opts=opts.SplitLineOpts (is_show=True),),) .add _ xaxis (xaxis_data=x) .add _ yaxis (series_name= "basic line chart", y_axis=y, symbol= "emptyCircle", is_symbol_show=True Label_opts=opts.LabelOpts (is_show=False),) line.render_notebook ()
Series_name: graphic name y_axis: data symbol: tagged graphics. The types provided by pyecharts include 'circle',' rect', 'roundRect',' triangle', 'diamond',' pin', 'arrow',' none', which can also be set to the picture through 'image://url', where URL is the link to the picture. Is_symbol_show: whether to display symbol2. Connect empty data (line chart)
Sometimes the data we want to analyze have blank values and need to be processed in order to draw a line chart.
Import pyecharts.options as optsfrom pyecharts.charts import Linex= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Wednesday', 'Sunday'] y = [100pjong 200pjrr400] line= (Line () .add _ xaxis (xaxis_data=x) .add _ yaxis (series_name= "connect empty data (line chart)", y_axis=y Is_connect_nones=True) .set _ global_opts (title_opts=opts.TitleOpts (title= "Line- connection empty data")) line.render_notebook ()
3. Multiple broken lines overlap import pyecharts.options as optsfrom pyecharts.charts import Linex= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Wednesday', 'Sunday'] y1 = [100200300400100400300] y2 = [200300200100100400400] line= (Line () .add _ xaxis (xaxis_data=x) .add _ yaxis (series_name= "Y1 line", yearly axisymmetric Y1 line symbol = "arrow", is_symbol_show=True) .add _ yaxis (series_name= "Y2 line") Y_axis=y2) .set _ global_opts (title_opts=opts.TitleOpts (title= "Line- Polyline overlap")) line.render_notebook ()
4. Smooth curve line chart import pyecharts.options as optsfrom pyecharts.charts import Linex= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Sunday'] y1 = [100200300400100400300] y2 = [200300200100100400400] line= (Line () .add _ xaxis (xaxis_data=x) .add _ yaxis (series_name= "Y1 line", y_axis=y1, is_smooth=True) .add _ yaxis (series_name= "y2 line", y_axis=y2) Is_smooth=True) .set _ global_opts (title_opts=opts.TitleOpts (title= "Line- Polyline overlap")) line.render_notebook ()
Is_smooth: smooth curve flag 5. Ladder diagram import pyecharts.options as optsfrom pyecharts.charts import Linex= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Sunday'] y1 = [100200300400100400300] line= (Line () .add _ xaxis (xaxis_data=x) .add _ yaxis (series_name= "Y1 line", y_axis=y1) Is_step=True) .set _ global_opts (title_opts=opts.TitleOpts (title= "Line- ladder")) line.render_notebook ()
Is_step: ladder diagram parameter 6. Change the style of the broken line import pyecharts.options as optsfrom pyecharts.charts import Linefrom pyecharts.faker import Fakerx= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Sunday'] y1 = [100200300400100400300] line = (Line () .add _ xaxis (xaxis_data=x) .add _ yaxis ("y1", y1, symbol= "triangle", symbol_size=30) Linestyle_opts=opts.LineStyleOpts (color= "red", width=4, type_= "dashed"), itemstyle_opts=opts.ItemStyleOpts (border_width=3, border_color= "yellow", color= "blue"),) .set _ global_opts (title_opts=opts.TitleOpts (title= "Line-ItemStyle")) line.render_notebook ()
Linestyle_opts: broken line style configuration color setting color, width setting width type setting type, there are three types of 'solid',' dashed', 'dotted' itemstyle_opts: element style configuration, border_width setting stroke width, border_color setting stroke color, color setting texture fill color 7. Broken-line area map import pyecharts.options as optsfrom pyecharts.charts import Linex= ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Wednesday', 'Sunday'] y1 = [100200300400100400300] y2 = [200300200100100400400] line= (Line () .add _ xaxis (xaxis_data=x) .add _ yaxis (series_name= "y1 line", series_name= "y1 line", yearly axisymmetric Y1 line areastyleopts. AreaStyleOpts (opacity=0.5)) .add _ yaxis (series_name= "y2 line"). Line.render_notebook _ global_opts (title_opts=opts.TitleOpts (title= "Line- Polyline overlap")
8. Double Abscissa line chart import pyecharts.options as optsfrom pyecharts.charts import Linefrom pyecharts.commons.utils import JsCodejs_formatter = "" function (params) {console.log (params); return 'precipitation' + params.value + (params.seriesData.length?':'+ params.seriesData [0] .data:'') Line= (Line (). Add _ xaxis (xaxis_data= ["2016-1", "2016-2", "2016-3", "2016-4", "2016-5", "2016-6", "2016-7", "2016-8") "2016-9", "2016-10", "2016-11", "2016-12",]. Extend _ axis (xaxis_data= ["2015-1", "2015-2", "2015-3", "2015-4", "2015-5") "2015-6", "2015-7", "2015-8", "2015-9", "2015-10", "2015-11", "2015-12", xaxis=opts.AxisOpts (type_= "category", axistick_opts=opts.AxisTickOpts (is_align_with_label=True) Axisline_opts=opts.AxisLineOpts (is_on_zero=False, linestyle_opts=opts.LineStyleOpts (color= "# 6e9ef1"), axispointer_opts=opts.AxisPointerOpts (is_show=True, label=opts.LabelOpts (formatter=JsCode (js_formatter)),),) .add _ yaxis (series_name= "2015 precipitation", is_smooth=True Symbol= "emptyCircle", is_symbol_show=False, color= "# d14a61", yawaxis = [2.6,5.9,9.0,26.4,28.7,70.7, 175.6, 182.2, 48.7,18.8,6.0,2.3], label_opts=opts.LabelOpts (is_show=False), linestyle_opts=opts.LineStyleOpts (width=2) ) .add _ yaxis (series_name= "2016 precipitation", is_smooth=True, symbol= "emptyCircle", is_symbol_show=False, color= "# 6e9ef1", yawaxis = [3.9,5.9,11.1,18.7,48.3,69.2, 231.6, 46.6,55.4,18.4,10.3,0.7] Label_opts=opts.LabelOpts (is_show=False), linestyle_opts=opts.LineStyleOpts (width=2),) .set _ global_opts (legend_opts=opts.LegendOpts (), tooltip_opts=opts.TooltipOpts (trigger= "none", axis_pointer_type= "cross"), xaxis_opts=opts.AxisOpts (type_= "category", axistick_opts=opts.AxisTickOpts (is_align_with_label=True)) Axisline_opts=opts.AxisLineOpts (is_on_zero=False, linestyle_opts=opts.LineStyleOpts (color= "# d14a61")), axispointer_opts=opts.AxisPointerOpts (is_show=True, label=opts.LabelOpts (formatter=JsCode (js_formatter), yaxis_opts=opts.AxisOpts (type_= "value") Splitline_opts=opts.SplitLineOpts (is_show=True, linestyle_opts=opts.LineStyleOpts (opacity=1)),),) line.render_notebook ()
9. Electricity consumption varies with time import pyecharts.options as optsfrom pyecharts.charts import Linex_data = ["00:00", "01:15", "02:30", "03:45", "05:00", "06:15", "07:30", "08 45", "10 15", "12 30", "1315", "1515" "16:15", "17:30", "18:45", "20:00", "21:15", "22:30", "23:45"] y_data = [300,280,250,260,270,550,500,400,390,380,390,400,500,750,800 700,600,400,] line= (Line () .add _ xaxis (xaxis_data=x_data) .add _ yaxis (series_name= "electricity consumption", y_axis=y_data, is_smooth=True, label_opts=opts.LabelOpts (is_show=False), linestyle_opts=opts.LineStyleOpts (width=2),) .set _ global_opts (title_opts=opts.TitleOpts (title= "one-day power consumption distribution" Subtitle= "pure fiction"), tooltip_opts=opts.TooltipOpts (trigger= "axis", axis_pointer_type= "cross"), xaxis_opts=opts.AxisOpts (boundary_gap=False), yaxis_opts=opts.AxisOpts (axislabel_opts=opts.LabelOpts (formatter= "{value} W"), splitline_opts=opts.SplitLineOpts (is_show=True),), visualmap_opts=opts.VisualMapOpts (is_piecewise=True, dimension=0) Pieces= [{"lte": 6, "color": "green"}, {"gt": 6, "lte": 8, "color": "red"}, {"gt": 8, "lte": 14, "color": "yellow"}, {"gt": 14, "lte": 17 "color": "red"}, {"gt": 17, "color": "green"},], pos_right=0, pos_bottom=100),) .set _ series_opts (markarea_opts=opts.MarkAreaOpts [opts.MarkAreaItem (name= "Morning Peak", x = ("07:30") "10:00"), opts.MarkAreaItem (name= "evening peak", x = ("17:30", "21:15"),])) line.render_notebook ()
Here are some key parameters:
① visualmap_opts: visual mapping configuration item, which can segment the broken line and set the label (is_piecewise), and set the color of different segments (pieces); ② markarea_opts: Mark the area configuration item, and the data parameter can set the tag area name and location. Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.