question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

2 Feature Requests: Plot Extra Grid Lines and deal with 'None' Values in Data Plot

See original GitHub issue

Hi,

The DateTime plot plot_date requires all values to be numeric (None/NaN/np.nan is not accepted), but it’s useful to be able to display shorter lines that don’t span the whole time frame, which requires a way to represent no data like None/NaN. What I’m trying to do is to add some arbitrary trend line/channel on a stock price series. Can you support this?

Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
NLKNguyencommented, Dec 24, 2021

Thanks for the quick response,

I realized I used your API incorrectly. There is no issue. I’m used to other chart libraries that require all time series to share the same time frame and where there is no data, a NaN or None is expected.

Turned out multiple plot_date can have different dates as long as each has the same data length and date length. Here is just for reference.

import pandas as pd
import plotext as plt

plt.datetime.set_datetime_form(date_form='%Y-%m-%d')

t1 = pd.date_range("2022-01-01", periods=5, freq="D")
x1 = [plt.datetime.datetime_to_string(el) for el in t1]
y1 = pd.Series([1,2,3,4,5], index=t1).tolist()
plt.plot_date(x1, y1,  marker = "hd", color=[1])

t2 = pd.date_range("2022-01-06", periods=5, freq="D") 
x2 = [plt.datetime.datetime_to_string(el) for el in t2]
y2 = pd.Series([6,7,8,9,10], index=t2).tolist()
plt.plot_date(x2, y2,  marker = "hd", color=[4])

t3 = pd.date_range("2022-01-03", periods=4, freq="D") 
x3 = [plt.datetime.datetime_to_string(el) for el in t3]
y3 = pd.Series([4,5,6,7], index=t3).tolist()
plt.plot_date(x3, y3,  marker = "hd", color=[3])

plt.canvas_color(0) 
plt.axes_color(0)
plt.ticks_color("bright-yellow")
plt.show()

image

Another question though, is there a way to show vertical lines on certain dates or horizontal lines on certain values? That would be similar to the existing Grid feature but only on specific locations.

Here is an example of an arbitrary vertical line when I use another lib called uniplot image

1reaction
piccolomocommented, Jan 1, 2022

Glad it worked 😃,

new 4.1.5 PyPi version also available.

Thanks, Savino

Read more comments on GitHub >

github_iconTop Results From Across the Web

4.5 The grid Package | Mastering Software Development in R
The book covers R software development for building data science tools. ... Grid graphics is a low-level system for plotting within R and...
Read more >
How to get rid of grid lines when plotting with Seaborn + ...
This is the best answer since you can use it with seaborn, pandas and matplotlib alike. Just call ax.grid(False) on whatever axes you...
Read more >
Matplotlib Adding Grid Lines - W3Schools
With Pyplot, you can use the grid() function to add grid lines to the plot. Example. Add grid lines to the plot: import...
Read more >
Chapter 4. Visualization with Matplotlib - O'Reilly
In [ 10 ]: # First create a grid of plots # ax will be an array of two Axes objects fig ,...
Read more >
Adding Grid Lines To The Plot | Matplotlib | Python Tutorials
In this Python Programming video tutorial you will learn about grid function of pyplot module in matplotlib package in detail.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found