why supply curve slope upward

Most supply and demand curves assume perfect competition.

An increase in Q (quantity, horizontal axis) means there is a bigger demand (in a competitive market), so price goes up.
On the other hand, when there is low demand for the commodity (Q goes to the left), suppliers tend to "dump" goods at a lower price.
All this result in a supply curve going upwards.
See, for example, further explanations at
https://en.wikipedia.org/wiki/Supply_and_demand

The upward slope of the supply curve is a reflection of the positive relationship between the price of a good or service and the quantity supplied. As the price of a product increases, suppliers are generally willing to produce and sell more of it. This relationship can be explained by several factors:

1. Production costs: As the price of a good increases, suppliers can afford to invest more in the production process, which may include hiring more workers, purchasing additional resources, or using more advanced technology. This increase in production costs is often referred to as the "law of diminishing returns." It means that suppliers must allocate more resources to produce each additional unit of output, resulting in higher costs. Therefore, they will only be willing to supply more when they can cover these higher costs by charging a higher price.

2. Profit motive: Suppliers are motivated by profit maximization. When the price of a good increases, their potential profit per unit sold increases as well. This creates an incentive for suppliers to increase their output and capture larger profits. Conversely, when the price of a good decreases, suppliers may not be able to cover their costs and may reduce their supply.

3. Opportunity cost: Suppliers have limited resources and must make choices about how to allocate those resources. When the price of a good increases, suppliers are more likely to allocate their resources to producing that good rather than alternative goods. This opportunity cost of producing one good instead of another reinforces the positive relationship between price and quantity supplied.

To determine the slope of the supply curve and understand how it changes, economists analyze empirical data and conduct statistical analysis. They collect information on prices and quantities supplied at different points in time and use regression analysis to estimate the slope and other factors affecting supply.