Python.Plotly)如何使用for语句在单个散点图上表示约45列的数据?

时间:2018-09-04 13:51:53

标签: python csv plotly

大家。 有人问我,是因为我想表达一个用度表示的图形,如下面的代码所示。下面,与csv文件中的列相关的值显示在图形上。 但是在下图中,只有几列,但是在我当前的项目中,我们将有约45列。 因此,如果列数较少,我想绘制一个如下图所示的图形,但是要绘制的图形太多。我写了代码,但我不知道该怎么做,所以我问了一个问题。我该怎么办?

如果您查看下面的代码, 这是用于绘制我们当前正在使用的图形的粗略代码形式。

import plotly.plotly as py
import plotly.graph_objs as go

import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/hobbs-pearson-trials.csv")


data = [
go.Scatterpolargl(
  r = df.trial_1_r,
  theta = df.trial_1_theta,
  mode = "markers",
  name = "Trial 1",
  marker = dict(
    color = "rgb(27,158,119)",
    size = 15,
    line = dict(
      color = "white"
    ),
    opacity = 0.7
  )
),
go.Scatterpolargl(
  r = df.trial_2_r,
  theta = df.trial_2_theta,
  mode = "markers",
  name = "Trial 2",
  marker = dict(
    color = "rgb(217,95,2)",
    size = 20,
    line = dict(
      color = "white"
    ),
    opacity = 0.7
  )
),
go.Scatterpolargl(
  r = df.trial_3_r,
  theta = df.trial_3_theta,
  mode = "markers",
  name = "Trial 3",
  marker = dict(
    color = "rgb(117,112,179)",
    size = 12,
    line = dict(
      color = "white"
    ),
    opacity = 0.7
  )
),
go.Scatterpolargl(
  r = df.trial_4_r,
  theta = df.trial_4_theta,
  mode = "markers",
  name = "Trial 4",
  marker = dict(
    color = "rgb(231,41,138)",
    size = 22,
    line = dict(
      color = "white"
    ),
    opacity = 0.7
  )
),
go.Scatterpolargl(
  r = df.trial_5_r,
  theta = df.trial_5_theta,
  mode = "markers",
  name = "Trial 5",
  marker = dict(
    color = "rgb(102,166,30)",
    size = 19,
    line = dict(
      color = "white"
    ),
    opacity = 0.7
  )
),
go.Scatterpolargl(
  r = df.trial_6_r,
  theta = df.trial_6_theta,
  mode = "markers",
  name = "Trial 6",
  marker = dict(
    color = "rgb(230,171,2)",
    size = 10,
    line = dict(
      color = "white"
    ),
    opacity = 0.7
  )
)
]

layout = go.Layout(
title = "Hobbs-Pearson Trials",
font = dict(
  size = 15
),
showlegend = False,
polar = dict(
  bgcolor = "rgb(223, 223, 223)",
  angularaxis = dict(
    tickwidth = 2,
    linewidth = 3,
    layer = "below traces"
  ),
  radialaxis = dict(
    side = "counterclockwise",
    showline = True,
    linewidth = 2,
    tickwidth = 2,
    gridcolor = "white",
    gridwidth = 2
  )
),
paper_bgcolor = "rgb(223, 223, 223)"
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='polar-webgl')

这是我当前在项目中使用的代码。 如果查看下面的代码,您将从csv文件中读取相应的信息。 但是,因为它有45列,所以我使用了论坛。但是从我们正在处理的代码中,我们在问自己如何绘制一个45列的图形。 我该怎么办?

import pandas as pd
import csv
import serial
import time

df = pd.read_csv("C:/Users/Jangsu/Desktop/ssssssssscccc.csv")

data = [
    for i in range(1,46):
        go.Scatterpolar(
        r=df["Save datas(Angle)"+str(i)],
        theta=str(i)+"°",
        mode="marker",
        name="Angle"+str(i)+"°",
        marker = dict(
        color = stored_angle[i]
        size = 15,
        line = dict(
          color = "white"
        ),
        opacity = 0.7
      )
]
layout = go.Layout(
   title = "Hobbs- Trials",
font = dict(
  size = 15
),
showlegend = False,
polar = dict(
  bgcolor = "rgb(255, 255, 255)",
  angularaxis = dict(
    tickwidth = 2,
    linewidth = 3,
    layer = "below traces"
  ),
  radialaxis = dict(
    side = "counterclockwise",
    showline = True,
    linewidth = 2,
    tickwidth = 2,
    gridcolor = "white",
    gridwidth = 2
  )
),
paper_bgcolor = "rgb(223, 223, 223)"
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='polar-webgl')

上面的代码现在由我决定。如何在绘制图形的地方绘制45列的图形? 供您参考,您可以在我离开的地址处检查要绘制的图形的类型。 https://plot.ly/python/polar-chart/

0 个答案:

没有答案