-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
I have a stacked dataset in a dataframe (1927 lines) with headings "Order", "Type", "CUSIP", "Date", "APY". I have used python code in a jupyter notebook to get a plot of Treasury Bill along with some money markets APYs. This past week, it failed; oddly. I use fig = px.line(df1, x="Date", y'="APY",..., color = "Type",...). This past week, instead of using values in column "APY" for the y coordinate, it is pulling some sort of internal integer counter. For instance, the most recent 3 datapoints for the 4-week T-Bill use integers y = 1, 2, 3, instead of the actual APY. When the program gets to the next "Type" (8-week T-Bill), it creates a new line on the plot (as it should) and starts over with y values of 1, 2, 3, .... The y value appears to be the row number within each group (identified by "Order" or "Type").
Very strangely, if I copy the code over to Spyder and add the lines:
import plotly.io as pio
pio.renderers.default = 'browser'
so the plot is outputted to my default browser, the code works fine, as it worked previously in jupyter notebook.
I am using
jupyterlab version 4.4.4
notebook version 7.4.4
python version 3.11.13
plotly version 6.0.1
I am using spyder version 6.0.7 with the same version of python and plotly.
CODE BELOW. I have hidden the path to the excel file. I have attached the excel file "StackedBillsMM.xlsx" with a single tab "Stacked Bills MM"
`import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
df1 = pd.read_excel('C:/Users/ ... /Treasury Auction data 2020s stacked.xlsx', 'Stacked Bills MM')
print(df1)
fig = px.line(df1, x="Date", y="APY", hover_data={"Date": "|%B %d, %Y"},
color = "Type",
color_discrete_sequence = ['black', 'red', 'orange', 'blue', 'green', 'purple'],
title='Treasury Bill APYs',
markers=True, width = 1700, height = 850
)
fig = fig.update_xaxes(
dtick="M1", ticks = 'outside', tickformat="%b\n%Y",
ticklabelmode="period", gridcolor='darkgrey', linecolor = 'black',
linewidth = 2, mirror = True, showline = True,
range = ["2024-08-10", "2025-09-19"],
title_font_size=22
)
fig = fig.update_yaxes(
tickformat=".1%", gridcolor='darkgrey', linecolor = 'black',
linewidth = 2, mirror = True, showline = True,
range = [0.0, 10.057],
title_font_size=20
)
fig = fig.update_layout(title={'y':0.92}, title_font={"size":24}, legend=dict(x=0.25, y=0.00), yaxis_range=[0.0,10.057])
fig = fig.update_layout(
yaxis = dict(tickfont = dict(size=18)),
xaxis = dict(tickfont = dict(size=20)),
plot_bgcolor='white', font_color="black",
legend = dict(font=dict(size=16), title = None)
)
#print(fig['data'])
fig['data'][0]['line']['width']=3; fig['data'][0]['marker']['size']=9
fig['data'][1]['line']['width']=2; fig['data'][1]['marker']['size']=6
fig['data'][6]['marker']['size']=1
fig['data'][7]['marker']['size']=1
fig['data'][8]['marker']['size']=1
fig['data'][9]['marker']['size']=1
fig.show()
import plotly.io as pio
pio.write_image(fig, "Bills.svg", scale=2.0)`