I have numpy.nparray data. I have CSV file genes.csv with data in format:
code
thrL;190;255
In data are coverage numbers. Turn data into bar chart(no labels) with ranges that are withing genes.csv red, and outside ranges blue. Keep in mind that python starts counting from 0, so do -1 for positions in csv file. Do not open the bar chart, render it into 1080p png image flatplot-both.png
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a Python script that uses NumPy and Matplotlib to create a bar chart with the specified requirements:
python
import numpy as np
import matplotlib.pyplot as plt
import csv
# Load data from genes.csv
gene_ranges = []
with open('genes.csv', 'r') as file:
reader = csv.reader(file, delimiter=';')
for row in reader:
start = int(row[1]) - 1
end = int(row[2]) - 1
gene_ranges.append((start, end))
# Create a mask for the gene ranges
mask = np.zeros_like(data, dtype='bool')
for start, end in gene_ranges:
mask[start:end+1] = True
# Create the bar chart
plt.figure(figsize=(19.2, 10.8)) # 1080p
plt.bar(range(len(data)), data, color=np.where(mask, 'red', 'blue'))
plt.axis('off') # Remove axis
plt.savefig('flatplot-both.png', bbox_inches='tight', dpi=100)
This script first loads the gene ranges from the CSV file and creates a mask for the gene ranges in the data array. Then, it creates a bar chart with the data array, using the mask to color the bars red for the gene ranges and blue for the non-gene ranges. Finally, it saves the bar chart to a PNG image file without displaying it.
Note: Make sure that the data array is defined and has the correct shape before running this script. Also, the genes.csv file should be in the same directory as the script, or you should provide the full path to the file.
User
Add appropriate vertical axis and on horisontal axis mark every million
Assistant
Here's the updated Python script:
python
import numpy as np
import matplotlib.pyplot as plt
import csv
# Load data from genes.csv
gene_ranges = []
with open('genes.csv', 'r') as file:
reader = csv.reader(file, delimiter=';')
for row in reader:
start = int(row[1]) - 1
end = int(row[2]) - 1
gene_ranges.append((start, end))
# Create a mask for the gene ranges
mask = np.zeros_like(data, dtype='bool')
for start, end in gene_ranges:
mask[start:end+1] = True
# Create the bar chart
plt.figure(figsize=(19.2, 10.8)) # 1080p
plt.bar(range(len(data)), data, color=np.where(mask, 'red', 'blue'))
plt.ylim(0, np.max(data) * 1.1) # Set vertical axis limits
plt.xticks(np.arange(0, len(data), 1e6), [f"{int(x/1e6)}M" for x in np.arange(0, len(data), 1e6)]) # Mark every million on horizontal axis
plt.xlabel("")
plt.ylabel("Coverage")
plt.savefig('flatplot-both.png', bbox_inches='tight', dpi=100)
This script adds a vertical axis with limits set to 10% above the maximum value in the data array, and marks every million on the horizontal axis with a label in the format "XM" (e.g., "1M", "2M", etc.). The horizontal axis label is removed, and a label is added to the vertical axis.