toga-chart icon indicating copy to clipboard operation
toga-chart copied to clipboard

xticks on figure

Open kufton opened this issue 2 years ago • 1 comments

Describe the bug

There seems to be no way to render a chart using pyplot.plot, you have to use the figure which doesn't allow for xticks or set_xticks. I'm running into a block to label the data with custom tick labels as a result of this.

Steps to reproduce

I've got user generated data from a function that just records input to a sqlite db.

data = cursor.execute("SELECT * FROM emotion_tracking ORDER BY datetime DESC limit 20").fetchall()
       if data:
           dates = [len(data) - data.index(row) for row in data]
           print(dates)
           states = [row[1] for row in data]
           self.dates = np.array(dates)[::-1]
           self.states = np.array(states)[::-1]
           self.labels = self.dates
       self.data = data

I've organised it so that the most recent will be displayed on the right hand side of the chart

The chart is built using this function.

def draw_chart(self, chart, figure, *args, **kwargs):
       print("in draw chart")
       # Draw the chart
       ax = figure.add_subplot(1,1,1)
       # ax.set_xticks(rotation = 90)
       ax.plot(self.dates, self.states)
       ax.set_xlabel('Date')
       ax.set_ylabel('EQ Score')
       ax.set_title('Daily Average Emotions Over Time')

This displays the chart:

Screenshot 2022-12-20 at 5 08 41 pm

When I change it to use dates, we get a big mess. Screenshot 2022-12-20 at 5 10 25 pm

I'm wanting to a aggregate the data (a numpy function I'm sure) but more importantly and the point of the ticket, display the days in a readable way, ideally roation=vertical.

Expected behavior

I was hoping to use plotly.plot but this creates a new window. using add_sublot doesn't allow for xticks or set_xticks on a subplot.

Screenshots

No response

Environment

  • Operating System: Mac OS 12.2
  • Python version: 3.9.12
  • Software versions:
    • Briefcase:0.3.11
    • Toga:0.3.0.dev39
    • Toga_chart: 0.1.1

Logs


Additional context

No response

kufton avatar Dec 20 '22 07:12 kufton

Reassigning as an enhancement, not a bug; while pyplot.plot() may be a common API, it's not the API we've documented for toga-canvas.

Support for pyplot.plot() would certainly be nice to have, though.

freakboy3742 avatar Dec 22 '22 00:12 freakboy3742