xticks on figure
- Dominant language
- Python
- Stars
- 30
- Forks
- 22
- Avg merge
- 3h 50m
- Merged PRs (30d)
- 2
Description
### 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:

When I change it to use dates, we get a big mess.

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_
Contributor guide
Research direction
Start with the supplied draw_chart example, especially figure.add_subplot(...), ax.plot(...), and the attempted ax.set_xticks call. Reproduce the date-label case with the provided Python and NumPy data, then inspect how the chart widget exposes matplotlib axes; done means subplot tick positioning and readable rotated labels work without opening a separate window.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, numpy, python, sqlite
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100