Python Forum
Points not plotting with reference to x-tick labels
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Points not plotting with reference to x-tick labels
#1
Here's the graphing portion of my program:
fig, axs = plt.subplots(1,1) 
fig.set_size_inches(14, 6)

axs.plot(trade_list,P_price_orig_all, marker='o', color='orange')
ax1twin = axs.twinx()
ax1twin.plot(btstats['Date'],btstats['SPX'],marker='',color='blue',linestyle='solid') #May still have to include y-axis label.
axs.set_xticks(list(np.linspace(1,len(btstats.index),num=len(xtick_labels_converted))),xtick_labels_converted, rotation=45)

plt.show()
I spend all those hours figuring out L7 to get evenly spaced (in time) dates to print out evenly spaced across the x-axis. However, trade_list (a list of dates) is not evenly spaced in time. These points print out evenly spaced--not in reference to the date values now shown on the x-axis:

https://ibb.co/z7021yD

What have I done?

Incidentally, if I comment out L5, the blue line goes away and the orange line/markers get compressed on the left side of the graph. This make some sense because len(trade_list) is 255 and len(btstats['SPX']) is 3449. I just want the 255 points to print accordingly where their x-values match up with those on the x-axis.
Reply
#2
We discussed in another thread from last week that ax.set_xticks() establishes a list of strings as the tick labels. What I'm seeing here is as if the values of the labels themselves aren't being registered. That would make sense if they're seen as strings as opposed to datetime objects. If I want the x-coordinates of the points to align with the x-axis, then maybe I can't use .set_xticks() here at all?

So basically... I want to plot the datetimes but I want the tick labels to be uniformly spread as opposed to appearing only when there's an x-coordinate to match (which would lead to irregular tick marks. We dealt with this in a thread a couple months ago).
Reply
#3
trade_list is also a list of strings so there's no way I can expect that to be plotted correctly on a datetime axis. I need to do further work on this. I think I need to convert those x-values to datetimes and then use an approach for the x-axis labels that preserves its datetime format.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get evenly-spaced datetime tick labels regardless of x-values of data points? Mark17 4 5,261 Apr-04-2022, 07:10 PM
Last Post: Mark17
  Floor division problem with plotting x-axis tick labels Mark17 5 2,117 Apr-03-2022, 01:48 PM
Last Post: Mark17
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,663 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
  Only show every nth tick in chart tgottsc1 1 4,688 Feb-01-2021, 04:30 PM
Last Post: j.crater
  Complex X Tick Interval JoeDainton123 0 1,480 Oct-05-2020, 07:27 PM
Last Post: JoeDainton123
  Setting Tick Intervals In Sub Plots JoeDainton123 1 1,812 Oct-03-2020, 11:52 PM
Last Post: scidam
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,569 Sep-07-2020, 08:02 AM
Last Post: perfringo
  Vpython Delay in plotting points SohaibAJ 0 2,073 Jul-30-2018, 08:44 PM
Last Post: SohaibAJ
  matplotlib barh y tick alignment iFunKtion 2 7,625 Oct-06-2016, 11:46 AM
Last Post: iFunKtion

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020