How to make a Python chart with only vertical and horizontal lines?


Chamber

How to draw something like this? Until the next data point appears, there seems to be a horizontal line followed by a vertical line to adjust the position y. The usual plotting function in matplotlib just draws a straight line between two data points and doesn't do what I need.

Example screenshot

the importance of conscientiousness

You can use one of the drawstyles "steps-pre", "steps-mid", "steps-post"to get the AA stepped curve look.

plt.plot(x,y, drawstyle="steps-pre")

Complete example:

import matplotlib.pyplot as plt
import numpy as np; np.random.seed()

x = np.arange(12)
y = np.random.rand(12)

styles = ["default","steps-pre","steps-mid", "steps-post"]

fig, axes = plt.subplots(nrows=len(styles), figsize=(4,7))

for ax, style in zip(axes, styles):
    ax.plot(x,y, drawstyle=style)
    ax.set_title("drawstyle={}".format(style))

fig.tight_layout()
plt.show()

enter image description here

Related


Horizontal and vertical lines only

Babak Abad I am new to Matlab. I have an image block as shown in the image below: The value of the white display pixel is equal to, 1and the value of the black display pixel is equal to 0, I want to get it vertical only lines. This means that the horizontal li

Horizontal and vertical lines only

Babak Abad I am new to Matlab. I have an image block as shown in the image below: The value of the white display pixel is equal to, 1and the value of the black display pixel is equal to 0, I want to get it vertical only lines. This means that the horizontal li

Horizontal and vertical lines only

Babak Abad I am new to Matlab. I have an image block as shown in the image below: The value of the white display pixel is equal to, 1and the value of the black display pixel is equal to 0, I want to get it vertical only lines. This means that the horizontal li

Horizontal and vertical lines only

Babak Abad I am new to Matlab. I have an image block as shown in the image below: The value of the white display pixel is equal to, 1and the value of the black display pixel is equal to 0, I want to get it vertical only lines. This means that the horizontal li

Horizontal and vertical lines only

Babak Abad I am new to Matlab. I have an image block as shown in the image below: The value of the white display pixel is equal to, 1and the value of the black display pixel is equal to 0, I want to get it vertical only lines. This means that the horizontal li

How to draw only vertical and horizontal lines (canvas)

Worstein Azatian I want to make a drawing tool with html5 canvas, it can only draw horizontal and vertical lines For example, although I will drag the mouse, it has to draw vertical or horizontal lines. Below I will show a picture where I will show what I need

how draw only vertical and horizontal lines (Canvas)

VostanAzatyan I want to make one drawing tool with html5 canvas, that can draw only horizontal and vertical lines For example despite which way I will drag the mouse it must draw vertical or horizontal line. Below I will show one image where i will show what i

How to draw only vertical and horizontal lines (canvas)

Worstein Azatian I want to make a drawing tool with html5 canvas, it can only draw horizontal and vertical lines For example, it has to draw vertical or horizontal lines despite which way I will drag the mouse. Below I will show an image where I will show what

How to draw only vertical and horizontal lines (canvas)

Worstein Azatian I want to make a drawing tool with html5 canvas, it can only draw horizontal and vertical lines For example, it has to draw vertical or horizontal lines despite which way I will drag the mouse. Below I will show an image where I will show what

How to make table only border lines and vertical lines html

Suman i need to make this table look like the blue line in the table in the picture is what i need please help me first thanks <style> td, th { text-align: left; padding: 8px; } table{ border: 1px solid #dddddd; } </style> <table> <tr> <th

How to make table only border lines and vertical lines html

Suman i need to make this table look like the blue line in the table in the picture is what i need please help me first thanks <style> td, th { text-align: left; padding: 8px; } table{ border: 1px solid #dddddd; } </style> <table> <tr> <th