How can I draw an energy ranking graph using Python?


twin penguins

This is a typical energy ranking used in some published papers, and I am struggling to reproduce one for my data using Python (any matplotlib, sns, etc.). I structure the data in a Pandas dataframe like this:

System  Color_id  Data1  Data2
Form I     1      0.0    0.6
Form II    2      0.8    0.0
Form III   3      2.1    2.7
Form IV    4      2.2    0.3
Form V     5      1.7    1.2

I added the "Color_id" column to enable specific_column_values ​​coloring in matplotlib, I think I'm only half way there with plt.scatter. What bothers me the most is drawing thin lines instead of typical markers, and how to automatically connect those dashed lines between similar systems of different data? Any help or advice is greatly appreciated.

Energy Ranking Chart

Aaron

I implemented an example that I suggested in the comments. This doesn't automatically scale the axis (I hardcoded it), and it doesn't add tick labels, but you should be able to find all of this in other questions.

import matplotlib.pyplot as plt
import numpy as np

def energy_rank(data, marker_width=.5, color='blue'):
    y_data = np.repeat(data, 2)
    x_data = np.empty_like(y_data)
    x_data[0::2] = np.arange(1, len(data)+1) - (marker_width/2)
    x_data[1::2] = np.arange(1, len(data)+1) + (marker_width/2)
    lines = []
    lines.append(plt.Line2D(x_data, y_data, lw=1, linestyle='dashed', color=color))
    for x in range(0,len(data)*2, 2):
        lines.append(plt.Line2D(x_data[x:x+2], y_data[x:x+2], lw=2, linestyle='solid', color=color))
    return lines

data = np.random.rand(4,8) * 4 # 4 lines with 8 datapoints from 0 - 4

artists = []
for row, color in zip(data, ('red','blue','green','magenta')):
    artists.extend(energy_rank(row, color=color))

fig, ax = plt.subplots()

for artist in artists:
    ax.add_artist(artist)
ax.set_ybound([0,4])
ax.set_xbound([.5,8.5])

Related


How can I draw an energy ranking graph using Python?

twin penguins This is a typical energy ranking used in some published papers, and I am struggling to reproduce one for my data using Python (any matplotlib, sns, etc.). I structure the data in a Pandas dataframe like this: System Color_id Data1 Data2 Form I

How can I draw an energy ranking graph using Python?

twin penguins This is a typical energy ranking used in some published papers, and I am struggling to reproduce one for my data using Python (any matplotlib, sns, etc.). I structure the data in a Pandas dataframe like this: System Color_id Data1 Data2 Form I

How can I draw such a graph in Python?

Santos I want to draw a graph like the image below: I wrote the following code to plot the waveform for each time step. import matplotlib.pyplot as plt import numpy as np def u_0(x): a = 1.0/np.cosh(2.0*(x+8.0)) b = 1.0/np.cosh((x+1.0)) return 8.0

How can I draw such a graph in Python?

Santos I want to draw a graph like the image below: I wrote the following code to plot the waveform for each time step. import matplotlib.pyplot as plt import numpy as np def u_0(x): a = 1.0/np.cosh(2.0*(x+8.0)) b = 1.0/np.cosh((x+1.0)) return 8.0

how can i draw graph in spring mvc in jsp using highchart

Francisco Gallardo: i want to draw graph in jsp unsando spring mvc and highchart but i still can't do it, i wait for your answer thanks My point, this is where I want to draw the graph, but the graph is not showing, it shows nothing <%@ taglib uri="http://java

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

how can i draw graph in spring mvc in jsp using highchart

Francisco Gallardo: i want to draw graph in jsp unsando spring mvc and highchart but i still can't do it, i wait for your answer thanks My point, this is where I want to draw the graph, but the graph is not showing, it shows nothing <%@ taglib uri="http://java

How can I draw this graph in Android using XML?

João Correia I'm trying to draw a form in an image in Android XML. But so far my attempts have been unsuccessful. what should I do? Thanks in advance place If you use RelativeLayout, you can make a black rectangle and put a white triangle image on top. I can't

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

how can i draw graph in spring mvc in jsp using highchart

Francisco Gallardo: i want to draw graph in jsp unsando spring mvc and highchart but i still can't do it, i wait for your answer thanks My point, this is where I want to draw the graph, but the graph is not showing, it shows nothing <%@ taglib uri="http://java

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

how can i draw graph in spring mvc in jsp using highchart

Francisco Gallardo: i want to draw graph in jsp unsando spring mvc and highchart but i still can't do it, i wait for your answer thanks My point, this is where I want to draw the graph, but the graph is not showing, it shows nothing <%@ taglib uri="http://java

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

How can I draw this graph using iris data?

Special case agency Using the iris dataset I want to draw a graph like this: Using viewport(), the scatter plot has a width and height of 0.66 I have two questions: 1.) As you can see in the second plot (right) the lines are smoother, but in the first plot (ri

How can I draw this graph in Android using XML?

João Correia I'm trying to draw a form in an image in Android XML. But so far my attempts have been unsuccessful. what should I do? Thanks in advance place If you use RelativeLayout, you can make a black rectangle and put a white triangle image on top. I can't

How can I fix my python code to draw the graph?

Joseph Tannuri My code exits with code 0, so my code has no errors, but it's still running without drawing the flow on the cylinder I want, can anyone help me with this? import sympy as s import matplotlib.pyplot as plt import numpy as np from

How can I fix my python code to draw the graph?

Joseph Tannuri My code exits with code 0, so my code has no errors, but it's still running without drawing the flow on the cylinder I want, can anyone help me with this? import sympy as s import matplotlib.pyplot as plt import numpy as np from

How can I fix my python code to draw the graph?

Joseph Tannuri My code exits with code 0, so my code has no errors, but it's still running without drawing the flow on the cylinder I want, can anyone help me with this? import sympy as s import matplotlib.pyplot as plt import numpy as np from

How can I fix my python code to draw the graph?

Joseph Tannuri My code exits with code 0, so my code has no errors, but it's still running without drawing the flow on the cylinder I want, can anyone help me with this? import sympy as s import matplotlib.pyplot as plt import numpy as np from

How can I fix my python code to draw the graph?

Joseph Tannuri My code exits with code 0, so my code has no errors, but it's still running without drawing the flow on the cylinder I want, can anyone help me with this? import sympy as s import matplotlib.pyplot as plt import numpy as np from

How can I draw this graph in Excel?

Pablo I have a CSV file with the following data This series has 500 rows. However, I need to plot whatever is on column A as the horizontal axis and whatever is on column B [0..499] as the vertical axis. I would like to label the horizontal axis values at ever

How can I draw a complete graph in R?

Mrsteve I want to draw complete graphs in R. How can I do this? I've only found one package on CRAN that has the ability to generate a full graph. But this package (i.e. "RnavGraph") is not installed but exits with error status. Further searching seems to be d

How can I draw this graph in R?

cooldood3490 I want to draw speedVS. Data are as follows:age Speed Age 15 <18 30 18-25 40 26-40 32 40+ How can I plot this as a scatterplot in R? I don't know how to do range. So far this is what I have. speed<-c(15,30,40,32) Peter Accu

How can I draw this graph in Excel?

Pablo I have a CSV file with the following data This series has 500 rows. However, I need to plot whatever is on column A as the horizontal axis and whatever is on column B [0..499] as the vertical axis. I would like to label the horizontal axis values at ever

How can I draw this graph in R?

cooldood3490 I want to draw speedVS. Data are as follows:age Speed Age 15 <18 30 18-25 40 26-40 32 40+ How can I plot this as a scatterplot in R? I don't know how to do range. So far this is what I have. speed<-c(15,30,40,32) Peter Accu

How to draw a directed graph using networkx in python?

Brainstorming: I have some nodes from a script that I want to map onto a graph. Below, I want to use "arrows" to go from A to D, and possibly also paint the edges red (red or something). Basically, it's like a path from A to D when all other nodes exist. You c