
Recherche avancée
Autres articles (65)
-
Participer à sa traduction
10 avril 2011Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
Actuellement MediaSPIP n’est disponible qu’en français et (...) -
Configurer la prise en compte des langues
15 novembre 2010, parAccéder à la configuration et ajouter des langues prises en compte
Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...) -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs
Sur d’autres sites (10444)
-
7 Reasons to Migrate from Google Analytics to Matomo Now
15 mai 2022, par Erin -
How to visualize matplotlib animation in Jupyter notebook
23 avril 2020, par anonymous13I am trying to create a racing bar chart similar to the one in the link (https://towardsdatascience.com/bar-chart-race-in-python-with-matplotlib-8e687a5c8a41). 
However I am unable to see the animation in my Jupyter notebook



code



import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.animation as animation
from IPython.display import HTML

df = pd.read_csv('https://gist.githubusercontent.com/johnburnmurdoch/4199dbe55095c3e13de8d5b2e5e5307a/raw/fa018b25c24b7b5f47fd0568937ff6c04e384786/city_populations', 
 usecols=['name', 'group', 'year', 'value'])

current_year = 2018
dff = (df[df['year'].eq(current_year)]
 .sort_values(by='value', ascending=True)
 .head(10))

colors = dict(zip(
 ['India', 'Europe', 'Asia', 'Latin America',
 'Middle East', 'North America', 'Africa'],
 ['#adb0ff', '#ffb3ff', '#90d595', '#e48381',
 '#aafbff', '#f7bb5f', '#eafb50']
))
group_lk = df.set_index('name')['group'].to_dict()


fig, ax = plt.subplots(figsize=(15, 8))
def draw_barchart(year):
 dff = df[df['year'].eq(year)].sort_values(by='value', ascending=True).tail(10)
 ax.clear()
 ax.barh(dff['name'], dff['value'], color=[colors[group_lk[x]] for x in dff['name']])
 dx = dff['value'].max() / 200
 for i, (value, name) in enumerate(zip(dff['value'], dff['name'])):
 ax.text(value-dx, i, name, size=14, weight=600, ha='right', va='bottom')
 ax.text(value-dx, i-.25, group_lk[name], size=10, color='#444444', ha='right', va='baseline')
 ax.text(value+dx, i, f'{value:,.0f}', size=14, ha='left', va='center')
 # ... polished styles
 ax.text(1, 0.4, year, transform=ax.transAxes, color='#777777', size=46, ha='right', weight=800)
 ax.text(0, 1.06, 'Population (thousands)', transform=ax.transAxes, size=12, color='#777777')
 ax.xaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,.0f}'))
 ax.xaxis.set_ticks_position('top')
 ax.tick_params(axis='x', colors='#777777', labelsize=12)
 ax.set_yticks([])
 ax.margins(0, 0.01)
 ax.grid(which='major', axis='x', linestyle='-')
 ax.set_axisbelow(True)
 ax.text(0, 1.12, 'The most populous cities in the world from 1500 to 2018',
 transform=ax.transAxes, size=24, weight=600, ha='left')
 ax.text(1, 0, 'by @pratapvardhan; credit @jburnmurdoch', transform=ax.transAxes, ha='right',
 color='#777777', bbox=dict(facecolor='white', alpha=0.8, edgecolor='white'))
 plt.box(False)

draw_barchart(2018)

import matplotlib.animation as animation
from IPython.display import HTML
fig, ax = plt.subplots(figsize=(15, 8))
animator = animation.FuncAnimation(fig, draw_barchart, frames=range(1968, 2019))
HTML(animator.to_jshtml()) 





Below is what I tried using and the errors



HTML(animator.to_jshtml()) <-- Static output with buttons unable to visualize animation
plt.rcParams["animation.html"] = "jshtml" <- no error and output
HTML(animator.to_html5_video()) <---Requested MovieWriter (ffmpeg) not available 





Note I have FFmpeg installed in my system.
Can you help me with the issue


-
Translating code snippet function from c++ to python, using ffmpeg to crop imageFile [closed]
5 octobre 2022, par MinaiThe code above is written in C++. It takes an input image file and crops its imageHeight and Width using ffmpeg libray, and saves the output image fractures to a txt file. I want the same code written in python. The fractures are saved using the new name of the original file plus the crop size to differentiate each image grid.


void shatterImages(string imagefiles, int imgWidth, int imgHeight, 
 int cropSizeW, int cropSizeH)
{
 cout << "Calculating subimage fractures for " << imagefiles << " fullframe images..." << endl;
 if(!imagefiles.isnull()){
 string outputCommand="";
 int i,j;
 ofstream myfile2 ("outputfile.txt");
 if (myfile2.is_open()) {
 //cout << "Fracturing: " << imagefiles << endl;
 outputCommand = "ffmpeg";
 for (i = 0; i < ceil(imgWidth / (0.0+cropSizeW)); i += 1) //loop vert over image
 {
 for (j = 0; j < ceil(imgHeight / (0.0+cropSizeH)); j += 1) //loop horizontally over image
 {
 //replace shattered images from fullframes to subframes
 outputCommand +=
 " -i " + imagefiles + " -qscale:v 1 -vf \"crop=" + to_string(cropSizeW) + ":" +
 to_string(cropSizeH) + ":" + to_string(i * cropSizeW) + ":" + to_string(j * cropSizeH) +
 "\" " + imagefiles.substr(0, imagefiles.length() - 4) + "-" +
 to_string(i * cropSizeW) + "-" + to_string(j * cropSizeH) + ".jpg";
 }
 }
 //print(outputCommand)
 myfile2 << outputCommand << endl;
 myfile2.close();
 cout << "Finished writing to: fractureAllImages.sh" << endl;
 }
 else
 cout << "Unable to open output file for: fractureAllImages.sh" << endl;
 }
}



I Transalted into python like this but I am getting an error :


import csv
from csv import reader, writer
from math import ceil
import string

#Using context managers to open file
with open ("coral.txt", 'w') as infile:
 outputFile = writer(infile)

 # writes to the file
 #infile.write('Test me, 123, abc, xyz')

 
#creating the main fucntion
def coral (imageFiles, imageWidth, imageHeight, cropWidth, cropHeight):
 print("calculating the subimage fractures for", imageFiles, "full frame images")
 
 if imageFiles != None:
 def outputCommand (i, j):
 outputFile.write("coral.txt")
 if (infile is open):
 print ("fracturing:", imageFiles)
 outputCommand = "ffmpeg"
 
 #looping vertically over the image
 for (i = 0, i < ceil(imageWidth/(0.0+cropWidth), i++)){

 #Looping horizontally over the image
 for (int j = 0; j(0.0+cropWidth); j++)){

 #replace shattered images from fullframes to subframes and saving
 outputCommand += " -i " + imageFiles + " -qscale:v 1 -vf \"crop=" + to_string(cropWidth) + ":" + to_string(cropHeight) + ":" + to_string(i * cropWidth) + ":" + to_string(j * cropHeight) + "\" " + imageFiles.substr(0, imageFiles.length() - 4) + "-" + to_string(i * cropWidth) + "-" + to_string(j * cropHeight) + ".jpg";
 
 }

 }


 
 #printing to the file coral.txt
 infile(outputCommand)
 infile.close() 
 print("Finnished writing to text file")
 

 else:
 print("Unable to open output file for fracturing")


#remember to close opened files
outputFile.close()