Ways to enhance the size of aircraft in Plotly

Upon analyzing the code snippet

import pandas as pd
import plotly.graph_objects as go
import numpy as np

df = pd.read_csv('https://raw.githubusercontent.com/tiago-peres/immersion/master/Platforms_dataset.csv')

fig = px.scatter_3d(df, x='Functionality ', y='Accessibility', z='Immersion', color='Platforms')

grey = [[0,'#C0C0C0'],[1,'#C0C0C0']]

zero_pt = pd.Series([0])
z = zero_pt.append(df['Immersion'], ignore_index = True).reset_index(drop = True)
y = zero_pt.append(df['Accessibility'], ignore_index = True).reset_index(drop = True)
x = zero_pt.append(df['Functionality '], ignore_index = True).reset_index(drop = True)

length_data = len(z)
z_plane_pos = 66.5*np.ones((length_data,length_data))

fig.add_trace(go.Surface(x=x, y=y, z=z_plane_pos, colorscale=grey,  showscale=False))
fig.add_trace(go.Surface(x=x.apply(lambda x: 15.69), y=y, z = np.array([z]*length_data), colorscale= grey, showscale=False))
fig.add_trace(go.Surface(x=x, y= y.apply(lambda x: 55), z =  np.array([z]*length_data).transpose(), colorscale=grey, showscale=False))

fig.update_layout(scene = dict(
        xaxis = dict(nticks=4, range=[0,31.38],),
        yaxis = dict(nticks=4, range=[0,110],),
        zaxis = dict(nticks=4, range=[0,133],),),
        legend_orientation="h",margin=dict(l=0, r=0, b=0, t=0))

This particular code can be accessed via Google Colab to generate a specific output.

https://i.stack.imgur.com/XHqPq.jpg

The planes illustrated in the output do not fill up the entire axis space as they should respect the axis ranges. In other words, the planes:

  • z=66.5 - should exist between [0, 31.38] in x and [0, 110] in y
  • x=15.59 - should exist between [0, 110] in y and [0, 133] in z
  • y=55 - should exist between [0, 31.38] in x and [0, 133] in z

How can this adjustment be made?


By implementing this new solution,

import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
import numpy as np

df = pd.read_csv('https://raw.githubusercontent.com/tiago-peres/immersion/master/Platforms_dataset.csv')

fig = px.scatter_3d(df, x='Functionality ', y='Accessibility', z='Immersion', color='Platforms')

grey = [[0,'#C0C0C0'],[1,'#C0C0C0']]

zero_pt = pd.Series([0])
z1 = np.arange(0, 134, 1)
print(z1)
y1 = np.arange(0, 111, 1)
print(z1)
x1 = np.arange(0, 32.38, 1)
print(z1)
z = zero_pt.append(df['Immersion'], ignore_index = True).reset_index(drop = True)
y = zero_pt.append(df['Accessibility'], ignore_index = True).reset_index(drop = True)
x = zero_pt.append(df['Functionality '], ignore_index = True).reset_index(drop = True)
print(zero_pt)
print(z)

test1 = pd.Series([133])
test = z.append(test1)

length_data1 = len(z1)
z_plane_pos = 66.5*np.ones((length_data1,length_data1))


length_data2 = len(y1)
y_plane_pos = 55*np.ones((length_data2,length_data2))


length_data3 = len(x1)
x_plane_pos = 15.69*np.ones((length_data3,length_data3))

fig.add_trace(go.Surface(x=x1, y=y1, z=z_plane_pos, colorscale=grey,  showscale=False))
fig.add_trace(go.Surface(x=x.apply(lambda x: 15.69), y=y1, z = np.array([test]*length_data1), colorscale= grey, showscale=False))
fig.add_trace(go.Surface(x=x1, y= y.apply(lambda x: 55), z =  np.array([test]*length_data1).transpose(), colorscale=grey, showscale=False))

fig.update_layout(scene = dict(
        xaxis = dict(nticks=4, range=[0,31.38],),
        yaxis = dict(nticks=4, range=[0,110],),
        zaxis = dict(nticks=4, range=[0,133],),),
        legend_orientation="h",margin=dict(l=0, r=0, b=0, t=0))

progress has been made but there is still an issue where planes x=15.59 and y=55 are not reaching the maximum value of 133 in Immersion.

https://i.stack.imgur.com/FkQc8.jpg

Answer №1

The issue arose from the incorrect shapes of the arrays I was trying to plot.

After separating the creation of input arrays and plotting, I identified the problem and then adjusted the size and content of the input arrays for proper plotting.

https://i.stack.imgur.com/MCXUc.png

import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
import numpy as np

df = pd.read_csv('https://raw.githubusercontent.com/tiago-peres/immersion/master/Platforms_dataset.csv')

zero_pt = pd.Series([0])
z1 = np.arange(0, 134, 1)
y1 = np.arange(0, 111, 1)
x1 = np.arange(0, 32.38, 1)
z = zero_pt.append(df['Immersion'], ignore_index=True).reset_index(drop=True)
y = zero_pt.append(df['Accessibility'], ignore_index=True).reset_index(drop=True)
x = zero_pt.append(df['Functionality '], ignore_index=True).reset_index(drop=True)

test1 = pd.Series([133])
test = z.append(test1)

length_data1 = len(z1)
z_plane_pos = 66.5*np.ones((length_data1,length_data1))
length_data2 = len(y1)
y_plane_pos = 55*np.ones((length_data2,length_data2))
length_data3 = len(x1)
x_plane_pos = 15.69*np.ones((length_data3,length_data3))

xvals = x.apply(lambda x: 15.69)
xvals2 = x1
yvals = y1
yvals2 = y.apply(lambda x: 55)
zvals = np.zeros((len(yvals), len(xvals)))
zvals[:, -1] = 133 
zvals2 = np.zeros((len(yvals2), len(xvals2)))
zvals2[-1, :] = 133

fig = px.scatter_3d(df, x='Functionality', y='Accessibility', z='Immersion', color='Platforms')
grey = [[0,'#C0C0C0'],[1,'#C0C0C0']]

fig.add_trace(go.Surface(x=x1, y=y1, z=z_plane_pos, colorscale=grey, showscale=False))
fig.add_trace(go.Surface(x=xvals, y=yvals, z=zvals, colorscale=grey, showscale=False))
fig.add_trace(go.Surface(x=xvals2, y=yvals2, z=zvals2, colorscale=grey, showscale=False))

fig.update_layout(scene=dict(
        xaxis=dict(nticks=4, range=[0,31.38]),
        yaxis=dict(nticks=4, range=[0,110]),
        zaxis=dict(nticks=4, range=[0,133]),),
        legend_orientation="h",margin=dict(l=0, r=0, b=0, t=0))

Check it out here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ordering results of Python script by location and grouping by shared identifier

There are numerous occurrences of data sharing the same location IDs, like in the output below where '3' is repeated multiple times: 121 {'data': {'id': 3, 'type': 'location'}, 'links': {&ap ...

Creating Lists Using Instances

Currently experimenting with list comprehension and facing a challenge. class Coder(): def __init__(self, name, years_at_college=1, scripts_written=0): self.name = name self.experience = years_at_college self.bonus_points = ra ...

A Python method for encoding "non-traditional" components of a URL using URL quoting

Below is the URL that I currently have: https://www.verizon.com/OnDemand/TVShows/TVShowDetails/Sr. Avila/1/9 I am looking to encode it in a way that makes it appear like a standard URL, while still remaining valid. For instance: https://www.verizon.com/ ...

What is the process for checking the status of the streaming source in GStreamer using Python?

I'm facing an issue with maintaining the streaming connection in gstreamer. I have a script that sets up pipeline elements to display live IP camera feed on screen. However, many times the stream from IP cameras abruptly stops, even though the camera ...

Double-click required to toggle button

Here is the code snippet for controlling an LED using a web page. The script, linked to Python, effectively controls the LED. However, there is an issue where the button toggles to the right side (ON position) only after a double click. Upon first click ...

How can we use Python and Selenium to retrieve the text from HTML that includes the <p> tag?

I have a simple question that I hope you can help me with. I'm not feeling well and struggling to complete my presentation because my brain just isn't functioning properly. Here is the HTML code in question: <p> <b>Postal code:& ...

Creating a matrix or table in Python to analyze overlapping data frames and count the intersections

Python seems to hold the key to a problem I encountered recently. dataframe 1 dataframe 2 dataframe 3 SID UID SID UID SID UID 123 dog 456 dog 789 monkey 123 cat 456 bat 789 ...

What is the method to execute Popen using a custom shell?

I have been developing a tool that is designed to execute a series of commands. These commands are written as if they were being entered into a terminal or console. In order to achieve this, I have utilized Popen() with the parameter shell=True to replica ...

Using polymorphism to replace Python conditionals

I recently came across some interesting code that illustrates how to replace conditionals with polymorphism. Here are the examples: Before: def log_msg(log_type): msg = 'Operation successful' if log_type == 'file': l ...

Using Pydantic to define models with both fixed and additional fields based on a Dict[str, OtherModel], mirroring the TypeScript [key: string] approach

Referencing a similar question, the objective is to construct a TypeScript interface that resembles the following: interface ExpandedModel { fixed: number; [key: string]: OtherModel; } However, it is necessary to validate the OtherModel, so using the ...

rearrange elements from a copied axis

Below is the code snippet in question: import pandas as pd from pandas import datetime from pandas import DataFrame as df import matplotlib from pandas_datareader import data as web import matplotlib.pyplot as plt import datetime TOKEN = "d0d2a3295349c62 ...

Issues connecting to servicenow have been detected

I encountered an error while attempting to connect to ServiceNow using JSON. Here is the code I am trying to execute: from servicenow import ServiceNow from servicenow import Connection conn = Connection.Auth(username='admin.main', password=&ap ...

How to organize dates in an Excel spreadsheet using Python

I am looking to extract specific data based on date from an imported excel file in Python. My goal is to provide a start and end date, and receive the data for that particular period. I have attempted various methods to install pandas_datareader in order t ...

Python 3 - Troubleshooting a problem with calling a class method externally

I've been on the hunt for a solution for quite some time now, and although I've come across a few potential fixes, none seem to address the specific issue that's causing trouble in my code. It's frustrating not being able to pinpoint ex ...

Extracting data from a JSON table and converting it into a Pandas dataframe using

Is it possible to extract data from this website in JSON format using BeautifulSoup? URL: import requests from bs4 import BeautifulSoup import pandas as pd r = requests.get(url) soup = BeautifulSoup(r.text, 'lxml') ...

Creating a Docker image for CoreOS (CP100A Training)

I am currently working on the labs for "Google Cloud Platform fundamentals" and encountering some issues. Every time I try to use a CoreOS instance to launch a Docker instance, I encounter an error. For instance, in the Cloud SQL lab, there is a step wher ...

Retrieving information from a text file using Python 3

I have created a script that saves players' names along with their scores. My goal is to retrieve this data back into Python for the purpose of organizing it into a table within a user interface. I believe there must be a straightforward solution, b ...

Exploring the process of reading multiple CSV files from various directories within Spark SQL

Having trouble reading multiple csv files from various folders from pyspark.sql import * spark = SparkSession \ .builder \ .appName("example") \ .config("spark.some.config.option") \ .getOrCreate( ...

Display contents from a JSON file

I need to extract unique locality values from a JSON file in Python, but my current code is only printing the first few entries and not iterating through all 538 elements. Here's what I have: import pandas as pd import json with open('data.json ...

Switch the type and version of the browser using Selenium

In an attempt to change my user agent using the Selenium Webdriver, I have utilized the following code. However, it has come to my attention that Google Analytics is able to easily detect my browser and its version (specifically Firefox 54.0 in this case). ...