Mar-01-2022, 09:50 PM
Here's some code:
Actually, I've been told before I want to print all points at once rather than iterate through... but the program needs to grab the corresponding marker from markerlist, which is why I say "iterate."
Also, I want this to be a line graph (solid is fine... I used dotted only because I stumbled upon that keyword string. In fact, maybe I don't even need to include that argument?). I tried this another way where I did iterate through the points (using a for i and .loc[] commands) and I lost the line connecting the dots (which I couldn't explain).
Any thoughts?
import datetime as dt import pandas as pd from matplotlib.ticker import LinearLocator df = pd.DataFrame({'date':[dt.datetime(2018,8,25), dt.datetime(2018,8,26), dt.datetime(2018,8,27), dt.datetime(2018,8,28), dt.datetime(2018,8,29), dt.datetime(2018,8,30), dt.datetime(2018,8,31), dt.datetime(2018,9,1), dt.datetime(2018,9,2), dt.datetime(2018,9,3), dt.datetime(2018,9,4)], 'n':[10, 6, 7, 2, -3, -5, 1, 3, 7, 10, 16]}) markerlist = [] trade_date = [dt.datetime(2018,8,25), dt.datetime(2018,8,30), dt.datetime(2018,9,3)] for i in df['date']: if i in trade_date: markerlist.append('d') else: markerlist.append('.') fig, ax = plt.subplots() ax.plot(df['date'], df['n'], marker=markerlist, linestyle='dashed', markersize=12) plt.xticks(rotation = 45) ax.get_xaxis().set_major_locator(LinearLocator(numticks=7)) #this works nicely to evenly space x-tick labels plt.show()This raises ValueError: Unrecognized marker style ['d', '.', '.', '.', '.', 'd', '.', '.', '.', 'd', '.']. What I really want is to iterate (?) through each point and plot accordingly.
Actually, I've been told before I want to print all points at once rather than iterate through... but the program needs to grab the corresponding marker from markerlist, which is why I say "iterate."
Also, I want this to be a line graph (solid is fine... I used dotted only because I stumbled upon that keyword string. In fact, maybe I don't even need to include that argument?). I tried this another way where I did iterate through the points (using a for i and .loc[] commands) and I lost the line connecting the dots (which I couldn't explain).
Any thoughts?