Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to draw six-dimensional stereogram with Python

Shulou Source: shulou.com Published: 2022-06-01 04:14:13 10月03日 Update

This article mainly explains "how to draw a six-dimensional picture with Python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to draw a six-dimensional picture with Python.

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.

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 pd

Data = 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 plotly

Import plotly.graph_objs as go

# drawing scatter plot

Fig1 = go.Scatter (x=data ['curb-weight']

Y=data ['price']

Mode='markers')

# draw layout

Mylayout = go.Layout (xaxis=dict (title= "curb-weight")

Yaxis=dict (title= "price"))

# drawing html

Plotly.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.

At this point, I believe you have a deeper understanding of "how to draw a six-dimensional stereogram with Python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: 3D Dimension data feature door Stereo Stereo two shape Code Price content engine can pass Circle Foundation size size Square method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Shulou Tech Info vpn Docker