This should do what you're asking for: # load the image image = pygame.image.load('someimage.png') # draw a yellow line on the image pygame.draw.line(image, (255, 255, 0), (0, 0), (100, 100)) Typically you don't draw to the original image, since you'll have to reload the image to get the original back (or create a copy of it before you start drawing onto it). Perhaps what you actually need is something more like this: # initialize pygame and screen import pygame pygame.init screen = pygame.display.setmode((720, 576)) # Draw the image to the screen screen.blit(image, (0, 0)) # Draw a line on top of the image on the screen pygame.draw.line(screen, (255, 255, 255), (0, 0), (50, 50)).
Getting Started Once you've installed the Notebook, you start from your terminal by calling $ jupyter notebook. This will open a browser on a to the URL of your Notebooks, by default. Windows users need to open up their Command Prompt. You'll see a dashboard with all your Notebooks. You can launch your Notebooks from there. The Notebook has the advantage of looking the same when you're coding and publishing. You just have all the options to move code, run cells, change kernels, and when you're running a NB.
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. If the pen is down, draw line. Do not change the. Instead of storing all the values you're trying to draw, it might be more efficient to just get the slope of the drawn line, and compute dashes at draw time.
Languages The bulk of this tutorial discusses executing python code in Jupyter notebooks. You can also use Jupyter notebooks to execute R code.
Skip down to the R section for more information on using IRkernel with Jupyter notebooks and graphing examples. Package Management When installing packages in Jupyter, you either need to install the package in your actual shell, or run the! Prefix, e.g.:!pip install packagename You may want to if you've edited the code in one. IPython comes with automatic reloading magic. You can reload all changed modules before executing a new line.%loadext autoreload%autoreload 2. Some useful packages that we'll use in this tutorial include:.: import data via a url and create a dataframe to easily handle data for analysis and graphing. See examples of using Pandas here:.: a package for scientific computing with tools for algebra, random number generation, integrating with databases, and managing data.
See examples of using NumPy here:.: a Python-based ecosystem of packages for math, science, and engineering.: a graphing library for making interactive, publication-quality graphs. See examples of statistic, scientific, 3D charts, and more here:. Import plotly.plotly as py import plotly.graphobjs as go tracewomen = go. Bar ( x = df.
School, y = df. Women, name = 'Women', marker = dict ( color = '#ffcdd2' )) tracemen = go. Bar ( x = df. School, y = df. Men, name = 'Men', marker = dict ( color = '#A2D5F2' )) tracegap = go. Bar ( x = df. School, y = df.
Gap, name = 'Gap', marker = dict ( color = '#59606D' )) data = tracewomen, tracemen, tracegap layout = go. Layout ( title = 'Average Earnings for Graduates', xaxis = dict ( title = 'School' ), yaxis = dict ( title = 'Salary (in thousands)' )) fig = go. Figure ( data = data, layout = layout ) py. Iplot ( fig, sharing = 'private', filename = 'jupyter-styledbar' ). Import plotly.plotly as py import plotly.graphobjs as go import pandas as pd # mapboxaccesstoken = 'ADD YOUR TOKEN HERE' df = pd. Readcsv ( '%20o n%20American%20Campuses.csv' ) sitelat = df. Lat sitelon = df.
Lon locationsname = df. Text data = go.
Scattermapbox ( lat = sitelat, lon = sitelon, mode = 'markers', marker = dict ( size = 17, color = 'rgb(255, 0, 0)', opacity = 0.7 ), text = locationsname, hoverinfo = 'text' ), go. Scattermapbox ( lat = sitelat, lon = sitelon, mode = 'markers', marker = dict ( size = 8, color = 'rgb(242, 177, 172)', opacity = 0.7 ), hoverinfo = 'none' ) layout = go. Layout ( title = 'Nuclear Waste Sites on Campus', autosize = True, hovermode = 'closest', showlegend = False, mapbox = dict ( accesstoken = mapboxaccesstoken, bearing = 0, center = dict ( lat = 38, lon =- 94 ), pitch = 0, zoom = 3, style = 'light' ), ) fig = dict ( data = data, layout = layout ) py. Iplot ( fig, filename = 'jupyter-Nuclear Waste Sites on American Campuses' ). Import plotly.plotly as py import plotly.graphobjs as go import numpy as np s = np. Linspace ( 0, 2. np.
Pi, 240 ) t = np. Linspace ( 0, np.
Pi, 240 ) tGrid, sGrid = np. Meshgrid ( s, t ) r = 2 + np. Sin ( 7. sGrid + 5. tGrid ) # r = 2 + sin(7s+5t) x = r.
np. Cos ( sGrid ).
np. Sin ( tGrid ) # x = r.cos(s).sin(t) y = r.
np. Sin ( sGrid ). np. Sin ( tGrid ) # y = r.sin(s).sin(t) z = r. np.
Cos ( tGrid ) # z = r.cos(t) surface = go. Surface ( x = x, y = y, z = z ) data = surface layout = go. Layout ( title = 'Parametric Plot', scene = dict ( xaxis = dict ( gridcolor = 'rgb(255, 255, 255)', zerolinecolor = 'rgb(255, 255, 255)', showbackground = True, backgroundcolor = 'rgb(230, 230,230)' ), yaxis = dict ( gridcolor = 'rgb(255, 255, 255)', zerolinecolor = 'rgb(255, 255, 255)', showbackground = True, backgroundcolor = 'rgb(230, 230,230)' ), zaxis = dict ( gridcolor = 'rgb(255, 255, 255)', zerolinecolor = 'rgb(255, 255, 255)', showbackground = True, backgroundcolor = 'rgb(230, 230,230)' ) ) ) fig = go. Figure ( data = data, layout = layout ) py.
Iplot ( fig, filename = 'jupyter-parametricplot' ).