In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use Python to draw a six-dimensional map, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Our brains usually perceive three-dimensional space at most, and it's hard to imagine more than three-dimensional. Although it is three-dimensional, it is difficult to understand, so two-dimensional planes are used in most cases.
From Wikipedia
However, we can still draw multi-dimensional space, so today we will use Python's plotly library to draw three-dimensional to six-dimensional diagrams to see what they look like. Python learns Qmuru-n 784, 758, 214 tutorials, videos, tools, and sharing of all kinds of practical operations
Data We use a real car data set from UCI, which includes 205samples and 26 features, from which 6 features are selected to draw the graph:
Basic work
Install the plotly package:
Pip install plotly
Load the dataset (provided at the end of the article):
Import pandas as pddata = pd.read_csv ("cars.csv")
Let's first draw a basic two-dimensional chart, using two RPM and Speed features:
Draw 2murd diagram
The code is implemented as follows:
Import plotlyimport plotly.graph_objs as go# drawing scatter fig1 = go.Scatter (x=data ['curb-weight'], y=data [' price'], mode='markers') # drawing layout mylayout = go.Layout (xaxis=dict (title= "curb-weight"), yaxis=dict (title= "price")) # drawing htmlplotly.offline.plot ({"data": [fig1] "layout": mylayout}, auto_open=True)
Save as html file open to generate an interactive interface, or you can save as a png picture.
Next, add features to draw a 3D diagram.
Draw 3murd diagram
You can use plotly's plot.Scatter3D method to draw a 3D map:
The code is implemented as follows:
Fig1 = go.Scatter3d (x=data ['curb-weight'], y=data [' horsepower'], z=data ['price'], marker=dict (opacity=0.9, reversescale=True, colorscale='Blues', size=5) Line=dict (width=0.02), mode='markers') mylayout = go.Layout (scene=dict (xaxis=dict (title= "curb-weight"), yaxis=dict (title= "horsepower"), zaxis=dict (title= "price"),) plotly.offline.plot ({"data": [fig1] "layout": mylayout}, auto_open=True, filename= ("3DPlot.html")
How to draw a graph with a higher dimension? Obviously not in the form of extended axes, but one trick is to create a virtual dimension that can be started with different colors, shapes, sizes, and shape categories. This allows you to display the fourth dimension.
Draw 4murd diagram
Next, we add the fourth variable, vehicle fuel consumption (city-mpg), to the original 3D diagram, represented by the color depth, so that the four-dimensional diagram is drawn. It can be seen that when the other three indicators (horsepower, body weight, car price) are higher: the vehicle fuel consumption is less.
Draw 5murd diagram
Based on this idea, we can also change the circle size to add another dimension-the engine size (engine-size) into a five-dimensional diagram:
We can still easily find the rule that the more expensive the car is, the bigger the engine size is.
Draw 6murd diagram
You can then add a sixth dimension-the number of doors-by changing the shape, with a circle representing four doors and a square representing two doors. Usually the two doors are expensive luxury sports cars, and it can be seen in the picture that the squares are mainly concentrated in areas with higher prices. Python learns Qmuru-n 784, 758, 214 tutorials, videos, tools, and sharing of all kinds of practical operations
In this way, we expand from ordinary two-dimensional graphics to high-dimensional graphics, of course, we can continue to expand, but it will be more and more difficult to distinguish.
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.
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.