0

enter image description here

import pyodbc
import pandas as pd
import matplotlib.pyplot as plt


conn = pyodbc.connect('Driver={SQL Server};' # This is what server type we are connecting to
                      'Server=DESKTOP-3JKKF7H;' # This is the location and name of the server, same as what we use to connect using SSMS
                      'Database=AdventureWorks2019;' # This is which database we are connecting to within the selected server
                      'Trusted_Connection=yes;') # This allows us to forgo entering a trusted key or password because we are the admin of this computer and the...
                    # ... database has been configured to allow this user when we set it up. 

cursor = conn.cursor()

query = 'SELECT * FROM Regional'

regional = pd.read_sql(query, conn)

print(regional.head())

regional.plot.barh(x='Region', y='Sales')
plt.xlabel("Sales (10s of millions)")


plt.show()
JRiggles
  • 4,847
  • 1
  • 12
  • 27
40_WPM
  • 43
  • 1
  • 5
  • 2
    Does this answer your question? [Prevent scientific notation](https://stackoverflow.com/questions/28371674/prevent-scientific-notation) – BigBen May 30 '23 at 13:38
  • it gave me this error when I tried that last suggestion Exception has occurred: KeyError "None of [Index([27150594589300.0, 18061660371000.0, 8913299247300.0, 8884099366900.0,\n 7820209628500.0],\n dtype='float64')] are in the [columns]" File "C:\Users\User\Desktop\Code example\Code Examples\Q1.py", line 23, in regional.plot.barh(x='Region', y=regional['Sales']*1e6) KeyError: "None of [Index([27150594589300.0, 18061660371000.0, 8913299247300.0, 8884099366900.0,\n 7820209628500.0],\n dtype='float64')] are in the [columns]" – 40_WPM May 30 '23 at 14:34
  • `plt.plot.barh(x=regional['Region'], y=regional['Sales']/1e6)` might work for you. – JohanC May 30 '23 at 21:10

1 Answers1

0

enter image description here

import numpy as np
import matplotlib.pyplot as plt

data = np.array([28E6, 17E6, 7E6, 6E6, 4E6])
labels = 'Southwest Northwest Central Southeast Northeast'.split()

fig, (ax0, ax1)  = plt.subplots(ncols=2, figsize=(10, 4))
fig.set_layout_engine('constrained')

ax0.barh(labels, data)
ax0.set_xlabel('Sales')

ax1.barh(labels, data/1E6)
ax1.set_xlabel('Sales, in Millions')

plt.show()
gboffi
  • 22,939
  • 8
  • 54
  • 85