René's URL Explorer Experiment


Title: Trying to replicate your movie and slider examples · Issue #1 · naveenv92/python-science-tutorial · GitHub

Open Graph Title: Trying to replicate your movie and slider examples · Issue #1 · naveenv92/python-science-tutorial

X Title: Trying to replicate your movie and slider examples · Issue #1 · naveenv92/python-science-tutorial

Description: I'm brand new at this. Trying to create animated and interactive graphics in a JupyterBook for a classroom text that I'm writing. I found your examples of the Fermi-Dirac distribution in your nice Medium article of last year. I can easil...

Open Graph Description: I'm brand new at this. Trying to create animated and interactive graphics in a JupyterBook for a classroom text that I'm writing. I found your examples of the Fermi-Dirac distribution in your nice ...

X Description: I'm brand new at this. Trying to create animated and interactive graphics in a JupyterBook for a classroom text that I'm writing. I found your examples of the Fermi-Dirac distribution in yo...

Opengraph URL: https://github.com/naveenv92/python-science-tutorial/issues/1

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Trying to replicate your movie and slider examples","articleBody":"I'm brand new at this. Trying to create animated and interactive graphics in a JupyterBook for a classroom text that I'm writing. I found your examples of the Fermi-Dirac distribution in your nice Medium article of last year.\r\n\r\nI can easily recreate the static diagram but when I try to create either the movie or the slider example I get errors. I've pasted in the two projects at the end of the first one (is that the right thing to do?) I'm working in Jupyter Lab, but my eventual target is JupyterBook. I'd appreciate some pointers.\r\n\r\nBTW I know that making it work in a notebook is not how to make it work interactively in JupyterBook. *If you have suggestions there, that would be very much appreciated!*\r\n\r\nI'm working on an M1 MacBook pro in, like I said, Jupyter Lab.\r\n\r\n```\r\nPython 3.8.8 (default, Apr 13 2021, 12:59:45) \r\n[Clang 10.0.0 ] :: Anaconda, Inc. on darwin\r\n```\r\n\r\nThanks in advance for your help and advice on web-embedding?\r\n\r\nHere are the code and results: \r\n\r\n**Movie:** \r\n\r\nAfter the lines:\r\n\r\n```\r\nmpl.rcParams['xtick.major.size'] = 10\r\nmpl.rcParams['xtick.major.width'] = 2\r\nmpl.rcParams['ytick.major.size'] = 10\r\nmpl.rcParams['ytick.major.width'] = 2\r\n```\r\n\r\nin the static program, I insert \r\n\r\n```\r\n# Change matplotlib backend\r\n%matplotlib notebook\r\n\r\n\r\n# Create figure and add axes\r\nfig = plt.figure(figsize=(6, 4))\r\nax = fig.add_subplot(111)\r\n\r\nand so on\r\n```\r\n through to the end of your movie example code. It produces errors:\r\n\r\n```\r\nJavascript Error: Can't find variable: IPython\r\n```\r\n\r\n```\r\nNameError                                 Traceback (most recent call last)\r\n\u003cipython-input-1-a0c46868fd22\u003e in \u003cmodule\u003e\r\n     76 \r\n     77 # Create animation\r\n---\u003e 78 ani = FuncAnimation(fig, animate, frames=range(len(T)), interval=500, repeat=True)\r\n     79 \r\n     80 # Ensure the entire plot is visible\r\n\r\nNameError: name 'FuncAnimation' is not defined\r\n```\r\n\r\n**Sliders**\r\n\r\nIn the same way, at the same point, I add the lines from the example:\r\n\r\n```\r\n\r\nfig = plt.figure(figsize=(6, 4.5))\r\n\r\n# Create main axis\r\nax = fig.add_subplot(111)\r\nfig.subplots_adjust(bottom=0.2, top=0.75)\r\n\r\n```\r\n and it produces a static picture of the plot with sliders (probably a slice of the animated gif from your article?) and errors\r\n\r\n```\r\nNameError                                 Traceback (most recent call last)\r\n\u003cipython-input-1-560d20080917\u003e in \u003cmodule\u003e\r\n     72 plt.show()\r\n     73 \r\n---\u003e 74 Slider.on_changed(func)\r\n\r\nNameError: name 'func' is not defined\r\n```\r\n\r\nHere are the complete cells for both\r\n\r\n**Movie**\r\n\r\n```\r\n# Import packages\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\n# Fermi-Dirac Distribution\r\ndef fermi(E: float, E_f: float, T: float) -\u003e float:\r\n    k_b = 8.617 * (10**-5) # eV/K\r\n    return 1/(np.exp((E - E_f)/(k_b * T)) + 1)\r\n\r\n# General plot parameters\r\nmpl.rcParams['font.family'] = 'Avenir'\r\nmpl.rcParams['font.size'] = 18\r\nmpl.rcParams['axes.linewidth'] = 2\r\nmpl.rcParams['axes.spines.top'] = False\r\nmpl.rcParams['axes.spines.right'] = False\r\nmpl.rcParams['xtick.major.size'] = 10\r\nmpl.rcParams['xtick.major.width'] = 2\r\nmpl.rcParams['ytick.major.size'] = 10\r\nmpl.rcParams['ytick.major.width'] = 2\r\n\r\n# Change matplotlib backend\r\n%matplotlib notebook\r\n\r\n\r\n# Create figure and add axes\r\nfig = plt.figure(figsize=(6, 4))\r\nax = fig.add_subplot(111)\r\n\r\n# Temperature values\r\nT = np.linspace(100, 1000, 10)\r\n\r\n# Get colors from coolwarm colormap\r\ncolors = plt.get_cmap('coolwarm', 10)\r\n\r\n# Plot F-D data\r\nfor i in range(len(T)):\r\n    x = np.linspace(0, 1, 100)\r\n    y = fermi(x, 0.5, T[i])\r\n    ax.plot(x, y, color=colors(i), linewidth=2.5)\r\n    \r\n# Add legend\r\nlabels = ['100 K', '200 K', '300 K', '400 K', '500 K', '600 K', \r\n          '700 K', '800 K', '900 K', '1000 K']\r\nax.legend(labels, bbox_to_anchor=(1.05, -0.1), loc='lower left', \r\n          frameon=False, labelspacing=0.2)\r\n\r\n# Create figure and add axes\r\nfig = plt.figure(figsize=(6, 4))\r\nax = fig.add_subplot(111)\r\n\r\n# Get colors from coolwarm colormap\r\ncolors = plt.get_cmap('coolwarm', 10)\r\n\r\n# Temperature values\r\nT = np.linspace(100, 1000, 10)\r\n\r\n# Create variable reference to plot\r\nf_d, = ax.plot([], [], linewidth=2.5)\r\n\r\n# Add text annotation and create variable reference\r\ntemp = ax.text(1, 1, '', ha='right', va='top', fontsize=24)\r\n\r\n# Set axes labels\r\nax.set_xlabel('Energy (eV)')\r\nax.set_ylabel('Fraction')\r\n\r\n# Animation function\r\ndef animate(i):\r\n    x = np.linspace(0, 1, 100)\r\n    y = fermi(x, 0.5, T[i])\r\n    f_d.set_data(x, y)\r\n    f_d.set_color(colors(i))\r\n    temp.set_text(str(int(T[i])) + ' K')\r\n    temp.set_color(colors(i))\r\n\r\n# Create animation\r\nani = FuncAnimation(fig, animate, frames=range(len(T)), interval=500, repeat=True)\r\n\r\n# Ensure the entire plot is visible\r\nfig.tight_layout()\r\n\r\n# Save and show animation\r\nani.save('AnimatedPlot.gif', writer='imagemagick', fps=2)\r\nplt.show()\r\n\r\n```\r\n\r\n**Sliders**\r\n\r\n```\r\n# Import packages\r\n%matplotlib inline\r\n\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.animation import FuncAnimation\r\nfrom matplotlib.widgets import Slider\r\nimport numpy as np\r\nimport networkx as nx\r\nfrom matplotlib.animation import FuncAnimation, PillowWriter \r\n\r\n# Fermi-Dirac Distribution\r\ndef fermi(E: float, E_f: float, T: float) -\u003e float:\r\n    k_b = 8.617 * (10**-5) # eV/K\r\n    return 1/(np.exp((E - E_f)/(k_b * T)) + 1)\r\n\r\n# General plot parameters\r\nmpl.rcParams['font.family'] = 'Avenir'\r\nmpl.rcParams['font.size'] = 18\r\n\r\nmpl.rcParams['axes.linewidth'] = 2\r\nmpl.rcParams['axes.spines.top'] = False\r\nmpl.rcParams['axes.spines.right'] = False\r\n\r\nmpl.rcParams['xtick.major.size'] = 10\r\nmpl.rcParams['xtick.major.width'] = 2\r\nmpl.rcParams['ytick.major.size'] = 10\r\nmpl.rcParams['ytick.major.width'] = 2\r\n\r\n\r\nfig = plt.figure(figsize=(6, 4.5))\r\n\r\n# Create main axis\r\nax = fig.add_subplot(111)\r\nfig.subplots_adjust(bottom=0.2, top=0.75)\r\n\r\n# Create axes for sliders\r\nax_Ef = fig.add_axes([0.3, 0.85, 0.4, 0.05])\r\nax_Ef.spines['top'].set_visible(True)\r\nax_Ef.spines['right'].set_visible(True)\r\n\r\nax_T = fig.add_axes([0.3, 0.92, 0.4, 0.05])\r\nax_T.spines['top'].set_visible(True)\r\nax_T.spines['right'].set_visible(True)\r\n\r\n# Create sliders\r\ns_Ef = Slider(ax=ax_Ef, label='Fermi Energy ', valmin=0, valmax=1.0, valinit=0.5, valfmt=' %1.1f eV', facecolor='#cc7000')\r\ns_T = Slider(ax=ax_T, label='Temperature ', valmin=100, valmax=1000, valinit=300, valfmt=' %i K', facecolor='#cc7000')\r\n\r\n# Plot default data\r\nx = np.linspace(-0, 1, 100)\r\nEf_0 = 0.5\r\nT_0 = 300\r\ny = fermi(x, Ef_0, T_0)\r\nf_d, = ax.plot(x, y, linewidth=2.5)\r\n\r\n\r\n# Update values\r\ndef update(val):\r\n    Ef = s_Ef.val\r\n    T = s_T.val\r\n    f_d.set_data(x, fermi(x, Ef, T))\r\n    fig.canvas.draw_idle()\r\n\r\ns_Ef.on_changed(update)\r\ns_T.on_changed(update)\r\n    \r\n# Set axis labels\r\nax.set_xlabel('Energy (eV)')\r\nax.set_ylabel('Fraction')\r\n\r\nplt.show()\r\n\r\nSlider.on_changed(func)\r\n\r\n```\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/chipbrock","@type":"Person","name":"chipbrock"},"datePublished":"2021-07-04T12:33:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1/python-science-tutorial/issues/1"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:05c5f862-17c8-0b80-a2a0-061bceea330a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE8B0:10CDC3:5FDE66:839C6C:698EF992
html-safe-nonce8066309e7757ef29efebf165df1ebc6cf83f8262ed069de5b5213487af28e324
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEIwOjEwQ0RDMzo1RkRFNjY6ODM5QzZDOjY5OEVGOTkyIiwidmlzaXRvcl9pZCI6IjU0NjI3Nzc1ODU2ODIyODI4OTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac69cd61ebbd09af127cd1ea2565e1d72f1b74a3aa3d73c06b984ba385add87a95
hovercard-subject-tagissue:936448043
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/naveenv92/python-science-tutorial/1/issue_layout
twitter:imagehttps://opengraph.githubassets.com/240c28dc0c4515be48c13648fcc440723cc53424b9308e52ba29227c73946592/naveenv92/python-science-tutorial/issues/1
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/240c28dc0c4515be48c13648fcc440723cc53424b9308e52ba29227c73946592/naveenv92/python-science-tutorial/issues/1
og:image:altI'm brand new at this. Trying to create animated and interactive graphics in a JupyterBook for a classroom text that I'm writing. I found your examples of the Fermi-Dirac distribution in your nice ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamechipbrock
hostnamegithub.com
expected-hostnamegithub.com
None7f7bf82d8907f81525d95af82e60354b419d083df9534c8631d06bb9c0bf07ac
turbo-cache-controlno-preview
go-importgithub.com/naveenv92/python-science-tutorial git https://github.com/naveenv92/python-science-tutorial.git
octolytics-dimension-user_id6731730
octolytics-dimension-user_loginnaveenv92
octolytics-dimension-repository_id252357369
octolytics-dimension-repository_nwonaveenv92/python-science-tutorial
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id252357369
octolytics-dimension-repository_network_root_nwonaveenv92/python-science-tutorial
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release29d97d94d5b31f96c01179273264722362f058e7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/issues/1#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnaveenv92%2Fpython-science-tutorial%2Fissues%2F1
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnaveenv92%2Fpython-science-tutorial%2Fissues%2F1
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=naveenv92%2Fpython-science-tutorial
Reloadhttps://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/issues/1
Reloadhttps://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/issues/1
Reloadhttps://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/issues/1
naveenv92 https://patch-diff.githubusercontent.com/naveenv92
python-science-tutorialhttps://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fnaveenv92%2Fpython-science-tutorial
Fork 76 https://patch-diff.githubusercontent.com/login?return_to=%2Fnaveenv92%2Fpython-science-tutorial
Star 149 https://patch-diff.githubusercontent.com/login?return_to=%2Fnaveenv92%2Fpython-science-tutorial
Code https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial
Issues 1 https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/issues
Pull requests 0 https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/pulls
Actions https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/actions
Projects 0 https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/projects
Security 0 https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/security
Insights https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/pulse
Code https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial
Issues https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/issues
Pull requests https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/pulls
Actions https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/actions
Projects https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/projects
Security https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/security
Insights https://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/naveenv92/python-science-tutorial/issues/1
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/naveenv92/python-science-tutorial/issues/1
Trying to replicate your movie and slider exampleshttps://patch-diff.githubusercontent.com/naveenv92/python-science-tutorial/issues/1#top
https://github.com/chipbrock
https://github.com/chipbrock
chipbrockhttps://github.com/chipbrock
on Jul 4, 2021https://github.com/naveenv92/python-science-tutorial/issues/1#issue-936448043
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.